Tag the CF Stack with SAM
Hi,
How to Tag the CF Stack which gets created by SAM? I can Tag the resources specified in the SAM CF Template, but I am unable to Tag the Cloudformation Stack. I used a work around by using awscli cloud formation update-stack, but that would fail if there are no changes.
Thanks in advance
I had the same problem, and also wanted to set the IAM Role property for the stack. The cloudformation deploy command doesn't offer either of these as options.
We worked around it by creating our stacks as pre-requisite steps using a non-SAM cloud formation templates. It just contains a very basic template with a temporary lambda function and role.
AWSTemplateFormatVersion: 2010-09-09
Description: Dummy template for new stacks
Resources:
role:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AWS::StackName}-temporary-role"
AssumeRolePolicyDocument:
Version : 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action: sts:AssumeRole
lambda:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: "Dummy code"
Handler: dummy
Role: !GetAtt role.Arn
Runtime: nodejs6.10
Then create the stack using the following command:
cloudformation create-stack --stack-name my-stack --template-url dummy-template.yaml --role-arn ... --tags ... --capabilities CAPABILITY_NAMED_IAM
This allows you to supply role-arn and tags arguments. Then once created, you can run your SAM deployment over the top.
Hi cluggas, Thanks for your reply. This approach wouldn't work for me since I am trying to automate the deployment through a CICD Pipeline and I wouldn't want to use 2 Templates to deploy a Serverless Resource. Regards
I agree it's not ideal. This was a compromise open to us, but I would be interested to know if you every solve this. Essentially I think it requires a feature request for tags and role to be supplied via the cloudofmration deploy command
Yep, agree. I was actually hoping that more people would miss the Tagging option for cloud formation deploy to get AWS to implement it.
Agree, need to be able to define the tags for the stack created.
A feature request has been submitted about a year ago to add --tags to the cloudformation deploy command, but updates on the status of the request for quite some time.
https://github.com/aws/aws-cli/issues/2324
It may be worth joining the conversation there in an attempt to increase its priority.
Closing this in favor of the AWS CLI Issue linked above. We are in the process of merging that in.