serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

Tag the CF Stack with SAM

Open c2xbrhdj6u4qs15 opened this issue 9 years ago • 7 comments

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

c2xbrhdj6u4qs15 avatar Aug 30 '17 17:08 c2xbrhdj6u4qs15

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.

cluggas avatar Sep 01 '17 14:09 cluggas

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

c2xbrhdj6u4qs15 avatar Sep 04 '17 07:09 c2xbrhdj6u4qs15

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

cluggas avatar Sep 04 '17 11:09 cluggas

Yep, agree. I was actually hoping that more people would miss the Tagging option for cloud formation deploy to get AWS to implement it.

c2xbrhdj6u4qs15 avatar Sep 05 '17 12:09 c2xbrhdj6u4qs15

Agree, need to be able to define the tags for the stack created.

kyrogue avatar Sep 28 '17 14:09 kyrogue

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.

davidrdark avatar Oct 08 '17 00:10 davidrdark

Closing this in favor of the AWS CLI Issue linked above. We are in the process of merging that in.

sanathkr avatar Jan 16 '18 19:01 sanathkr