Skip to content

[0.47.0] Template with Cloudwatch Rule Enable/Disable Parameter does not override the status #1948

Closed

Description

@lmayorga1980

I am trying to deploy a sam template that has a Cloudwatch Rule that is supposed to be enabled in prod account but disabled in a sandbox account.

AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: |
  MY LAMBDA FUNCTION
Parameters:
  EnableCWRule:
    Description: Enable Cloudwatch Rule.
    Default: 'false'
    Type: String
    AllowedValues:
      - 'true'
      - 'false'
Conditions:
  EnableCloudWatchRule: !Equals
    - !Ref EnableCWRule
    - 'true'

Globals:
  Function:
    Timeout: 60
Resources:
  MYLAMBDAROLE:
    Type: 'AWS::IAM::Role'
    Properties:
      Path: /MY-LAMBDAS/
      RoleName: MYLAMBDAROLE
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
                - events.amazonaws.com
            Action: 'sts:AssumeRole'
      Policies:
        - PolicyName: MYLAMBDAPOLICY
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource: 'arn:aws:logs:*:*:log-group:/aws/lambda/*:*:*'
              - Effect: Allow
                Action:
                  - 'ec2:ModifyImageAttribute'
                Resource: '*'
  MYFUNCTION:
    Type: 'AWS::Serverless::Function'
    Properties:
      CodeUri: src/
      Handler: myfunction.lambda_handler
      Runtime: python3.7
      Role: !GetAtt MYLAMBDAROLE.Arn
      Events:
        TRIGGERCWRULE:
          Properties:
            Schedule: cron(0 4 * * ? *)
            Enabled: !If EnableCloudWatchRule
          Type: Schedule

Outputs:
  MYFUNCTIONOUTPUT:
    Description: MY FUNCTION
    Value: !GetAtt
      - MYFUNCTION
      - Arn

sam deploy

sam deploy --s3-bucket myfunctions-bucket --stack-name my-function-stack --profile myprofile --region us-east-1 --capabilities CAPABILITY_NAMED_IAM --parameter-overrides EnableCWRule=false

Currently, the Cloudwatch Rule is enabled=true and when I run the sam-cli command, it should switch to enable=false. Instead I am getting the following...

        Deploying with following values
        ===============================
        Stack name                 : My-function-stack
        Region                     : us-east-1
        Confirm changeset          : False
        Deployment s3 bucket       :  myfunctions-bucket
        Capabilities               : ["CAPABILITY_NAMED_IAM"]
        Parameter overrides        : {'EnableCWRule': 'false'}

Initiating deployment
=====================

Waiting for changeset to be created..
No changes to deploy. Stack my-function-stack is up to date

🤔 Is there a workaround to pass boolean parameters to my sam deployment process.

Thanks.

Activity

  1. changed the title [-][0.47.0] Template with Cloudwatch Rule Enable/Disable Parameter does not update the status[/-] [+][0.47.0] Template with Cloudwatch Rule Enable/Disable Parameter does not override the status[/+] on Apr 28, 2020
  2. sriram-mv commented on May 6, 2020

    @sriram-mv
    Contributor

    You shouldn't need that condition, you should be able to directly !Ref?

  3. limitusus commented on Nov 5, 2020

    @limitusus
  4. z0ph commented on Nov 24, 2020

    @z0ph

    You shouldn't need that condition, you should be able to directly !Ref?

    Even using only !Ref, the value is empty.

  5. jewelsjacobs commented on Dec 1, 2020

    @jewelsjacobs

    FWIW, I have a bash script function workaround. It will remove the lambda CloudWatch Event rule trigger and disable the rule itself for SAM rules with the default serverlessrepo*. names. It should be easy to add parameters / variables to.

    I can't find an AWS CLI way to just disable a CloudWatch Event in the Lambda so I remove it.

    https://gist.github.com/jewelsjacobs/2ea1b37dd4db5279d038111e77d9d813

  6. lmayorga1980 commented on Apr 29, 2021

    @lmayorga1980
    Author

    FWIW, I have a bash script function workaround. It will remove the lambda CloudWatch Event rule trigger and disable the rule itself for SAM rules with the default serverlessrepo*. names. It should be easy to add parameters / variables to.

    I can't find an AWS CLI way to just disable a CloudWatch Event in the Lambda so I remove it.

    https://gist.github.com/jewelsjacobs/2ea1b37dd4db5279d038111e77d9d813

    Your gist is not available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions