To fully manage the existing resource with your CDK stack (allowing you to modify its properties later), you must perform a Resource Import using the cdk import CLI command, which relies on CloudFormation's import capabilities.
Let's test this with new cdk code, importing a sns topic.
cdk init app --language=python
Create venv
source .venv/bin/activate && pip install -r requirements.txt
We would like import this resource
On the cdk code you need to write the following, referencing the topic.
Run cdk synth to see the cloudformation template
cdk synth
Resources:
MyManagedTopic0CEB7327:
Type: AWS::SNS::Topic
Properties:
TopicName: MyTopic
Metadata:
aws:cdk:path: CdkImportStack/MyManagedTopic/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Analytics: v2:deflate64:H4sIAAAAAAAA/zPcxxxxxxx
Metadata:
aws:cdk:path: CdkImportStack/CDKMetadata/Default
Parameters:
BootstrapVersion:
Type: AWS::SSM::Parameter::Value<String>
Default: /cdk-bootstrap/hnb659fds/version
Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
Then run and it will ask for the topic arn
cdk import CdkImportStack
You will see on the cloudformation stack the resource imported
No hay comentarios:
Publicar un comentario