Repository navigation
Closed
Labels
Description
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
- Arnsam 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.
Reacted by ObiH15
Activity
[-][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[/+]sriram-mv commentedon May 6, 2020
You shouldn't need that condition, you should be able to directly !Ref?
limitusus commentedon Nov 5, 2020
Seems same as #2150 and aws/serverless-application-model#1329
z0ph commentedon Nov 24, 2020
Even using only
!Ref, the value is empty.jewelsjacobs commentedon Dec 1, 2020
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
lmayorga1980 commentedon Apr 29, 2021
Your gist is not available.