Let's imagine you have a SAM template to your App, and for some reason you created manually resources. And you want to manage those resources created already into your template.
The steps should be as follow:
- Grab the code of the stack.
- Create a file with the CloudFormation code that you already have, remove the transform tag. And add the code of what you want to import, in this case we are importing a DynamoDB table.AWSTemplateFormatVersion: '2010-09-09'Description: SAM Template with DynamoDB Table and SNS TopicResources:MySNSTopic:Type: AWS::SNS::TopicProperties:TopicName: MyNotificationTopicMetadata:SamResourceId: MySNSTopicSecondaryTable:Type: AWS::DynamoDB::TableDeletionPolicy: RetainProperties:TableName: SecondaryTableBillingMode: PAY_PER_REQUESTAttributeDefinitions:- AttributeName: idAttributeType: SKeySchema:- AttributeName: idKeyType: HASH
- Go to the stack actions -> Import resources into the stack.
- Choose your CF template.
- Enter the name of the dynamodb table.
- You will see a brief of the import.
- The import will be completed.
- Then update your SAM Template.AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31Description: SAM Template with DynamoDB Table and SNS TopicResources:MySNSTopic:Type: AWS::SNS::TopicProperties:TopicName: MyNotificationTopicSecondaryTable:Type: AWS::DynamoDB::TableDeletionPolicy: RetainProperties:TableName: SecondaryTableBillingMode: PAY_PER_REQUESTAttributeDefinitions:- AttributeName: idAttributeType: SKeySchema:- AttributeName: idKeyType: HASH
- Run sam build and sam deploy.
- It will be managed by SAM now.
No hay comentarios:
Publicar un comentario