diff --git a/changelog.md b/changelog.md index 00db4fe5..2e6a2da9 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 9.2.0 + +- Inline policy for Lambda Shortcut name will change from `${LogicalName}-lambda-log-access` to `${AWS::StackName}-${LogicalName}-lambda-log-access`. This is the new default value. You can override default value using property `LogPolicyName`. + ## 9.1.1 - Add DeletionPolicy for the IAM Policy in Lamdba shortcuts. diff --git a/lib/shortcuts/api.md b/lib/shortcuts/api.md index dcfabe1d..04f2abd7 100644 --- a/lib/shortcuts/api.md +++ b/lib/shortcuts/api.md @@ -425,6 +425,7 @@ Log Group, a Role, an Alarm on function errors, and the Lambda Function itself. | [options.OKActions] | Array.<String> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-okactions). | | [options.LogRetentionInDays] | Number | 14 | How long to retain CloudWatch logs for this Lambda function. See [AWS Documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html) for allowed values. | | [options.LogPolicyDeletionPolicy] | String | 'Delete' | DeletionPolicy on the IAM Policy resource used to access Logs. See [AWS Documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-deletionpolicy.html) for allowed values. | +| [options.LogPolicyName] | String | '${stack-name}-${logical-name}-lambda-log-access' | The name of the IAM Policy used to access CloudWatch Logs. | **Example** ```js diff --git a/lib/shortcuts/lambda.js b/lib/shortcuts/lambda.js index 4fbb4f19..9153296b 100644 --- a/lib/shortcuts/lambda.js +++ b/lib/shortcuts/lambda.js @@ -49,6 +49,7 @@ const ServiceRole = require('./service-role'); * @param {Array} [options.OKActions=undefined] - See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-okactions). * @param {Number} [options.LogRetentionInDays=14] - How long to retain CloudWatch logs for this Lambda function. See [AWS Documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html) for allowed values. * @param {String} [options.LogPolicyDeletionPolicy='Delete'] - DeletionPolicy on the IAM Policy resource used to access Logs. See [AWS Documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-deletionpolicy.html) for allowed values. + * @param {String} [options.LogPolicyName='${stack-name}-${logical-name}-lambda-log-access'] - The name of the IAM Policy used to access CloudWatch Logs. * @example * const cf = require('@mapbox/cloudfriend'); * @@ -109,7 +110,8 @@ class Lambda { ExtendedStatistic, OKActions, LogRetentionInDays = 14, - LogPolicyDeletionPolicy = 'Delete' + LogPolicyDeletionPolicy = 'Delete', + LogPolicyName = { 'Fn::Sub': `\${AWS::StackName}-${LogicalName}-lambda-log-access` } } = options; if (options.EvaluationPeriods < Math.ceil(Timeout / Period)) @@ -205,7 +207,7 @@ class Lambda { DependsOn: (RoleArn) ? undefined : `${LogicalName}Role`, DeletionPolicy: LogPolicyDeletionPolicy, Properties: { - PolicyName: `${LogicalName}-lambda-log-access`, + PolicyName: LogPolicyName, Roles: [roleName], PolicyDocument: { Version: '2012-10-17', diff --git a/package-lock.json b/package-lock.json index 5a62f940..17b26b1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mapbox/cloudfriend", - "version": "9.1.1", + "version": "9.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@mapbox/cloudfriend", - "version": "9.1.1", + "version": "9.2.0", "license": "ISC", "dependencies": { "@aws-sdk/client-cloudformation": "^3.848.0", diff --git a/package.json b/package.json index 7550cc97..eff09a0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mapbox/cloudfriend", - "version": "9.1.1", + "version": "9.2.0", "description": "Helper functions for assembling CloudFormation templates in JavaScript", "main": "index.js", "engines": { diff --git a/test/fixtures/shortcuts/event-lambda-custom-eventbus.json b/test/fixtures/shortcuts/event-lambda-custom-eventbus.json index 452cdd82..ac44f430 100644 --- a/test/fixtures/shortcuts/event-lambda-custom-eventbus.json +++ b/test/fixtures/shortcuts/event-lambda-custom-eventbus.json @@ -88,7 +88,7 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" }, "Roles": [ { "Ref": "MyLambdaRole" diff --git a/test/fixtures/shortcuts/event-lambda-defaults.json b/test/fixtures/shortcuts/event-lambda-defaults.json index 7ec91292..1803ee63 100644 --- a/test/fixtures/shortcuts/event-lambda-defaults.json +++ b/test/fixtures/shortcuts/event-lambda-defaults.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -197,4 +199,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/event-lambda-full.json b/test/fixtures/shortcuts/event-lambda-full.json index 7bce6588..3cffbfbd 100644 --- a/test/fixtures/shortcuts/event-lambda-full.json +++ b/test/fixtures/shortcuts/event-lambda-full.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -197,4 +199,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-github-compatible-legacy-node-runtimes.json b/test/fixtures/shortcuts/hookshot-github-compatible-legacy-node-runtimes.json index 17353e97..bdedadef 100644 --- a/test/fixtures/shortcuts/hookshot-github-compatible-legacy-node-runtimes.json +++ b/test/fixtures/shortcuts/hookshot-github-compatible-legacy-node-runtimes.json @@ -226,7 +226,7 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" }, "Roles": [ { "Ref": "PassFunctionRole" @@ -368,7 +368,7 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" }, "Roles": [ { "Ref": "DestinationRole" diff --git a/test/fixtures/shortcuts/hookshot-github-secret-ref.json b/test/fixtures/shortcuts/hookshot-github-secret-ref.json index 7ce83ff3..e54c8543 100644 --- a/test/fixtures/shortcuts/hookshot-github-secret-ref.json +++ b/test/fixtures/shortcuts/hookshot-github-secret-ref.json @@ -28,7 +28,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -47,7 +47,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -232,7 +232,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -374,7 +376,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -430,4 +434,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-github-secret-string.json b/test/fixtures/shortcuts/hookshot-github-secret-string.json index 408025ed..34527a62 100644 --- a/test/fixtures/shortcuts/hookshot-github-secret-string.json +++ b/test/fixtures/shortcuts/hookshot-github-secret-string.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -43,7 +43,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -226,7 +226,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -368,7 +370,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -422,4 +426,4 @@ "Value": "abc123" } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-github.json b/test/fixtures/shortcuts/hookshot-github.json index 7522a9c6..26a4d442 100644 --- a/test/fixtures/shortcuts/hookshot-github.json +++ b/test/fixtures/shortcuts/hookshot-github.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -43,7 +43,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -234,7 +234,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -376,7 +378,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -432,4 +436,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-passthrough-access-log-format.json b/test/fixtures/shortcuts/hookshot-passthrough-access-log-format.json index 0557177a..8ff0c691 100644 --- a/test/fixtures/shortcuts/hookshot-passthrough-access-log-format.json +++ b/test/fixtures/shortcuts/hookshot-passthrough-access-log-format.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -52,7 +52,7 @@ } } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -230,7 +230,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -372,7 +374,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -428,4 +432,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-passthrough-alarms.json b/test/fixtures/shortcuts/hookshot-passthrough-alarms.json index ee76376a..c2e961a0 100644 --- a/test/fixtures/shortcuts/hookshot-passthrough-alarms.json +++ b/test/fixtures/shortcuts/hookshot-passthrough-alarms.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -43,7 +43,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -214,7 +214,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -356,7 +358,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -412,4 +416,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-passthrough-compatible-legacy-node-runtimes.json b/test/fixtures/shortcuts/hookshot-passthrough-compatible-legacy-node-runtimes.json index 6614b22c..0d19b05d 100644 --- a/test/fixtures/shortcuts/hookshot-passthrough-compatible-legacy-node-runtimes.json +++ b/test/fixtures/shortcuts/hookshot-passthrough-compatible-legacy-node-runtimes.json @@ -212,7 +212,7 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" }, "Roles": [ { "Ref": "PassFunctionRole" @@ -354,7 +354,7 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" }, "Roles": [ { "Ref": "DestinationRole" diff --git a/test/fixtures/shortcuts/hookshot-passthrough-enhanced-logging.json b/test/fixtures/shortcuts/hookshot-passthrough-enhanced-logging.json index c588e5c9..7c0dd64d 100644 --- a/test/fixtures/shortcuts/hookshot-passthrough-enhanced-logging.json +++ b/test/fixtures/shortcuts/hookshot-passthrough-enhanced-logging.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -43,7 +43,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -212,7 +212,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -354,7 +356,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -410,4 +414,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-passthrough-full-blown-logging.json b/test/fixtures/shortcuts/hookshot-passthrough-full-blown-logging.json index bfb22eb8..4372508b 100644 --- a/test/fixtures/shortcuts/hookshot-passthrough-full-blown-logging.json +++ b/test/fixtures/shortcuts/hookshot-passthrough-full-blown-logging.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -43,7 +43,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -212,7 +212,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -354,7 +356,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -410,4 +414,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-passthrough-logging.json b/test/fixtures/shortcuts/hookshot-passthrough-logging.json index e2fdd86c..8ce832af 100644 --- a/test/fixtures/shortcuts/hookshot-passthrough-logging.json +++ b/test/fixtures/shortcuts/hookshot-passthrough-logging.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -43,7 +43,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -212,7 +212,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -354,7 +356,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -410,4 +414,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/hookshot-passthrough.json b/test/fixtures/shortcuts/hookshot-passthrough.json index 2cbac34a..8b2dfac9 100644 --- a/test/fixtures/shortcuts/hookshot-passthrough.json +++ b/test/fixtures/shortcuts/hookshot-passthrough.json @@ -24,7 +24,7 @@ "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "PassDeploymentbdbc0f16" + "Ref": "PassDeployment6d7d2c50" }, "StageName": "hookshot", "RestApiId": { @@ -43,7 +43,7 @@ ] } }, - "PassDeploymentbdbc0f16": { + "PassDeployment6d7d2c50": { "Type": "AWS::ApiGateway::Deployment", "DependsOn": "PassMethod", "Properties": { @@ -212,7 +212,9 @@ "DependsOn": "PassFunctionRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "PassFunction-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-PassFunction-lambda-log-access" + }, "Roles": [ { "Ref": "PassFunctionRole" @@ -354,7 +356,9 @@ "DependsOn": "DestinationRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "Destination-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-Destination-lambda-log-access" + }, "Roles": [ { "Ref": "DestinationRole" @@ -410,4 +414,4 @@ } } } -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/lambda-defaults.json b/test/fixtures/shortcuts/lambda-defaults.json index 7018d3a6..68f35a39 100644 --- a/test/fixtures/shortcuts/lambda-defaults.json +++ b/test/fixtures/shortcuts/lambda-defaults.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -131,4 +133,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/lambda-docker.json b/test/fixtures/shortcuts/lambda-docker.json index 57f7061a..cd0d62ea 100644 --- a/test/fixtures/shortcuts/lambda-docker.json +++ b/test/fixtures/shortcuts/lambda-docker.json @@ -86,7 +86,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -129,4 +131,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/lambda-full.json b/test/fixtures/shortcuts/lambda-full.json index deffd5f5..fd473f7d 100644 --- a/test/fixtures/shortcuts/lambda-full.json +++ b/test/fixtures/shortcuts/lambda-full.json @@ -122,7 +122,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -181,4 +183,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/lambda-provided-role.json b/test/fixtures/shortcuts/lambda-provided-role.json index fb54554b..9b638567 100644 --- a/test/fixtures/shortcuts/lambda-provided-role.json +++ b/test/fixtures/shortcuts/lambda-provided-role.json @@ -87,7 +87,9 @@ "Type": "AWS::IAM::Policy", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Fn::Select": [ @@ -131,4 +133,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/lambda-zipfile.json b/test/fixtures/shortcuts/lambda-zipfile.json index 4cda0c44..67fcacf2 100644 --- a/test/fixtures/shortcuts/lambda-zipfile.json +++ b/test/fixtures/shortcuts/lambda-zipfile.json @@ -87,7 +87,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -130,4 +132,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/log-subscription-lambda-defaults.json b/test/fixtures/shortcuts/log-subscription-lambda-defaults.json index a3629f98..835b63d6 100644 --- a/test/fixtures/shortcuts/log-subscription-lambda-defaults.json +++ b/test/fixtures/shortcuts/log-subscription-lambda-defaults.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -167,4 +169,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/log-subscription-lambda-no-defaults.json b/test/fixtures/shortcuts/log-subscription-lambda-no-defaults.json index b410daf9..71fbbee3 100644 --- a/test/fixtures/shortcuts/log-subscription-lambda-no-defaults.json +++ b/test/fixtures/shortcuts/log-subscription-lambda-no-defaults.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -167,4 +169,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/queue-lambda-zero.json b/test/fixtures/shortcuts/queue-lambda-zero.json index a3683054..dbb801d5 100644 --- a/test/fixtures/shortcuts/queue-lambda-zero.json +++ b/test/fixtures/shortcuts/queue-lambda-zero.json @@ -89,7 +89,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -172,4 +174,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/queue-lambda.json b/test/fixtures/shortcuts/queue-lambda.json index 8974f19c..d0f39e73 100644 --- a/test/fixtures/shortcuts/queue-lambda.json +++ b/test/fixtures/shortcuts/queue-lambda.json @@ -89,7 +89,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -172,4 +174,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/scheduled-lambda-defaults.json b/test/fixtures/shortcuts/scheduled-lambda-defaults.json index f5b2ab62..b5a0bb56 100644 --- a/test/fixtures/shortcuts/scheduled-lambda-defaults.json +++ b/test/fixtures/shortcuts/scheduled-lambda-defaults.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -206,4 +208,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/scheduled-lambda-full.json b/test/fixtures/shortcuts/scheduled-lambda-full.json index ef4781fd..6ffcc127 100644 --- a/test/fixtures/shortcuts/scheduled-lambda-full.json +++ b/test/fixtures/shortcuts/scheduled-lambda-full.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -164,4 +166,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/stream-lambda-defaults.json b/test/fixtures/shortcuts/stream-lambda-defaults.json index d92775b9..c1ad6b58 100644 --- a/test/fixtures/shortcuts/stream-lambda-defaults.json +++ b/test/fixtures/shortcuts/stream-lambda-defaults.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -177,4 +179,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/fixtures/shortcuts/stream-lambda-no-defaults.json b/test/fixtures/shortcuts/stream-lambda-no-defaults.json index e10ea3d9..39d642ae 100644 --- a/test/fixtures/shortcuts/stream-lambda-no-defaults.json +++ b/test/fixtures/shortcuts/stream-lambda-no-defaults.json @@ -88,7 +88,9 @@ "DependsOn": "MyLambdaRole", "DeletionPolicy": "Delete", "Properties": { - "PolicyName": "MyLambda-lambda-log-access", + "PolicyName": { + "Fn::Sub": "${AWS::StackName}-MyLambda-lambda-log-access" + }, "Roles": [ { "Ref": "MyLambdaRole" @@ -185,4 +187,4 @@ } }, "Outputs": {} -} +} \ No newline at end of file diff --git a/test/shortcuts.test.js b/test/shortcuts.test.js index a51fbb2b..2d07a821 100644 --- a/test/shortcuts.test.js +++ b/test/shortcuts.test.js @@ -218,6 +218,22 @@ test('[shortcuts] lambda', (assert) => { 'expected resources generated using no default values' ); + lambda = new cf.shortcuts.Lambda({ + LogicalName: 'MyLambda', + Code: { + S3Bucket: 'my-code-bucket', + S3Key: 'path/to/code.zip' + }, + LogPolicyName: 'CustomLogPolicyName' + }); + + template = cf.merge(lambda); + assert.equal( + template.Resources.MyLambdaLogPolicy.Properties.PolicyName, + 'CustomLogPolicyName', + 'LogPolicyName parameter correctly overrides the default policy name' + ); + assert.end(); });