forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cloudwatch-actions): multiple alarms with LambdaAction for the sa…
…me Lambda fail (under feature flag) (aws#28712) Multiple alarms with LambdaAction for the same Lambda fail, because of the same logical IDs for generated lambda permissions. ```ts alarmConcurrentLambdasMaximumReached.addAlarmAction(new awsCloudWatchActions.LambdaAction(lambda)); alarmRdsCpuUtilizationMaximumReached.addAlarmAction(new awsCloudWatchActions.LambdaAction(lambda)); ``` ``` throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`); ^ Error: There is already a Construct with name 'AlarmPermission' in NodejsFunction [...] ``` Since the existing logical IDs would change, I implemented this with a feature flag. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
2076e53
commit ce07b8f
Showing
14 changed files
with
919 additions
and
186 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...alarm-action.js.snapshot/LambdaAlarmActionIntegrationTestStackWithFeatureFlag.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
355 changes: 355 additions & 0 deletions
355
...arm-action.js.snapshot/LambdaAlarmActionIntegrationTestStackWithFeatureFlag.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,355 @@ | ||
{ | ||
"Resources": { | ||
"inAlarmLambdaFeatureServiceRoleA2CD21D1": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"inAlarmLambdaFeature6C78D351": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = function handler(event, _context, callback) {\n console.log(JSON.stringify(event, undefined, 2));\n return callback();\n}" | ||
}, | ||
"FunctionName": "inAlarmLambdaFeature", | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"inAlarmLambdaFeatureServiceRoleA2CD21D1", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs18.x" | ||
}, | ||
"DependsOn": [ | ||
"inAlarmLambdaFeatureServiceRoleA2CD21D1" | ||
] | ||
}, | ||
"Alarm7103F465": { | ||
"Type": "AWS::CloudWatch::Alarm", | ||
"Properties": { | ||
"ActionsEnabled": true, | ||
"AlarmActions": [ | ||
{ | ||
"Ref": "alarmLambdaFeatureCurrentVersionCF39751979501d2f67eaf906b2ef0c378303873b" | ||
}, | ||
{ | ||
"Ref": "alarmLambdaFeatureAliasaliasName16F91D34" | ||
}, | ||
{ | ||
"Fn::GetAtt": [ | ||
"alarmLambdaFeatureD560800F", | ||
"Arn" | ||
] | ||
} | ||
], | ||
"ComparisonOperator": "GreaterThanThreshold", | ||
"Dimensions": [ | ||
{ | ||
"Name": "FunctionName", | ||
"Value": { | ||
"Ref": "inAlarmLambdaFeature6C78D351" | ||
} | ||
} | ||
], | ||
"EvaluationPeriods": 1, | ||
"MetricName": "Errors", | ||
"Namespace": "AWS/Lambda", | ||
"Period": 60, | ||
"Statistic": "Sum", | ||
"Threshold": 1, | ||
"TreatMissingData": "notBreaching" | ||
} | ||
}, | ||
"alarmLambdaFeatureServiceRole853A864D": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"alarmLambdaFeatureD560800F": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "exports.handler = function handler(event, _context, callback) {\n console.log(JSON.stringify(event, undefined, 2));\n return callback();\n}" | ||
}, | ||
"FunctionName": "alarmLambdaFeature", | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"alarmLambdaFeatureServiceRole853A864D", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs18.x" | ||
}, | ||
"DependsOn": [ | ||
"alarmLambdaFeatureServiceRole853A864D" | ||
] | ||
}, | ||
"alarmLambdaFeatureCurrentVersionCF39751979501d2f67eaf906b2ef0c378303873b": { | ||
"Type": "AWS::Lambda::Version", | ||
"Properties": { | ||
"FunctionName": { | ||
"Ref": "alarmLambdaFeatureD560800F" | ||
} | ||
} | ||
}, | ||
"alarmLambdaFeatureCurrentVersionAlarmAlarmPermissionA0D80E66": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Ref": "alarmLambdaFeatureCurrentVersionCF39751979501d2f67eaf906b2ef0c378303873b" | ||
}, | ||
"Principal": "lambda.alarms.cloudwatch.amazonaws.com", | ||
"SourceAccount": { | ||
"Ref": "AWS::AccountId" | ||
}, | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"Alarm7103F465", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"alarmLambdaFeatureCurrentVersionAlarmFeatureAlarmPermission192451B4": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Ref": "alarmLambdaFeatureCurrentVersionCF39751979501d2f67eaf906b2ef0c378303873b" | ||
}, | ||
"Principal": "lambda.alarms.cloudwatch.amazonaws.com", | ||
"SourceAccount": { | ||
"Ref": "AWS::AccountId" | ||
}, | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"AlarmFeature9DD74C42", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"alarmLambdaFeatureAliasaliasName16F91D34": { | ||
"Type": "AWS::Lambda::Alias", | ||
"Properties": { | ||
"FunctionName": { | ||
"Ref": "alarmLambdaFeatureD560800F" | ||
}, | ||
"FunctionVersion": { | ||
"Fn::GetAtt": [ | ||
"alarmLambdaFeatureCurrentVersionCF39751979501d2f67eaf906b2ef0c378303873b", | ||
"Version" | ||
] | ||
}, | ||
"Name": "aliasName" | ||
} | ||
}, | ||
"alarmLambdaFeatureAliasaliasNameAlarmAlarmPermissionE344338D": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Ref": "alarmLambdaFeatureAliasaliasName16F91D34" | ||
}, | ||
"Principal": "lambda.alarms.cloudwatch.amazonaws.com", | ||
"SourceAccount": { | ||
"Ref": "AWS::AccountId" | ||
}, | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"Alarm7103F465", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"alarmLambdaFeatureAliasaliasNameAlarmFeatureAlarmPermission6A0A5797": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Ref": "alarmLambdaFeatureAliasaliasName16F91D34" | ||
}, | ||
"Principal": "lambda.alarms.cloudwatch.amazonaws.com", | ||
"SourceAccount": { | ||
"Ref": "AWS::AccountId" | ||
}, | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"AlarmFeature9DD74C42", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"alarmLambdaFeatureAlarmAlarmPermissionCF637A1C": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Fn::GetAtt": [ | ||
"alarmLambdaFeatureD560800F", | ||
"Arn" | ||
] | ||
}, | ||
"Principal": "lambda.alarms.cloudwatch.amazonaws.com", | ||
"SourceAccount": { | ||
"Ref": "AWS::AccountId" | ||
}, | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"Alarm7103F465", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"alarmLambdaFeatureAlarmFeatureAlarmPermission7032FB2D": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"FunctionName": { | ||
"Fn::GetAtt": [ | ||
"alarmLambdaFeatureD560800F", | ||
"Arn" | ||
] | ||
}, | ||
"Principal": "lambda.alarms.cloudwatch.amazonaws.com", | ||
"SourceAccount": { | ||
"Ref": "AWS::AccountId" | ||
}, | ||
"SourceArn": { | ||
"Fn::GetAtt": [ | ||
"AlarmFeature9DD74C42", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"AlarmFeature9DD74C42": { | ||
"Type": "AWS::CloudWatch::Alarm", | ||
"Properties": { | ||
"ActionsEnabled": true, | ||
"AlarmActions": [ | ||
{ | ||
"Ref": "alarmLambdaFeatureCurrentVersionCF39751979501d2f67eaf906b2ef0c378303873b" | ||
}, | ||
{ | ||
"Ref": "alarmLambdaFeatureAliasaliasName16F91D34" | ||
}, | ||
{ | ||
"Fn::GetAtt": [ | ||
"alarmLambdaFeatureD560800F", | ||
"Arn" | ||
] | ||
} | ||
], | ||
"ComparisonOperator": "GreaterThanThreshold", | ||
"Dimensions": [ | ||
{ | ||
"Name": "FunctionName", | ||
"Value": { | ||
"Ref": "inAlarmLambdaFeature6C78D351" | ||
} | ||
} | ||
], | ||
"EvaluationPeriods": 1, | ||
"MetricName": "Errors", | ||
"Namespace": "AWS/Lambda", | ||
"Period": 60, | ||
"Statistic": "Sum", | ||
"Threshold": 1, | ||
"TreatMissingData": "notBreaching" | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ambdaAlarmActionIntegrationTestWithFeatureFlagDefaultTestDeployAssertB72D1A4A.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.