Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/shortcuts/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ Log Group, a Role, an Alarm on function errors, and the Lambda Function itself.
| [options.OKActions] | <code>Array.&lt;String&gt;</code> | | See [AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-okactions). |
| [options.LogRetentionInDays] | <code>Number</code> | <code>14</code> | 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] | <code>String</code> | <code>&#x27;Delete&#x27;</code> | 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] | <code>String</code> | <code>&#x27;${stack-name}-${logical-name}-lambda-log-access&#x27;</code> | The name of the IAM Policy used to access CloudWatch Logs. |

**Example**
```js
Expand Down
6 changes: 4 additions & 2 deletions lib/shortcuts/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ServiceRole = require('./service-role');
* @param {Array<String>} [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');
*
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions test/fixtures/shortcuts/event-lambda-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -197,4 +199,4 @@
}
},
"Outputs": {}
}
}
6 changes: 4 additions & 2 deletions test/fixtures/shortcuts/event-lambda-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -197,4 +199,4 @@
}
},
"Outputs": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 9 additions & 5 deletions test/fixtures/shortcuts/hookshot-github-secret-ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentbdbc0f16"
"Ref": "PassDeployment6d7d2c50"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -47,7 +47,7 @@
]
}
},
"PassDeploymentbdbc0f16": {
"PassDeployment6d7d2c50": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -430,4 +434,4 @@
}
}
}
}
}
14 changes: 9 additions & 5 deletions test/fixtures/shortcuts/hookshot-github-secret-string.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentbdbc0f16"
"Ref": "PassDeployment6d7d2c50"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentbdbc0f16": {
"PassDeployment6d7d2c50": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -422,4 +426,4 @@
"Value": "abc123"
}
}
}
}
14 changes: 9 additions & 5 deletions test/fixtures/shortcuts/hookshot-github.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentbdbc0f16"
"Ref": "PassDeployment6d7d2c50"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentbdbc0f16": {
"PassDeployment6d7d2c50": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -432,4 +436,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentbdbc0f16"
"Ref": "PassDeployment6d7d2c50"
},
"StageName": "hookshot",
"RestApiId": {
Expand Down Expand Up @@ -52,7 +52,7 @@
}
}
},
"PassDeploymentbdbc0f16": {
"PassDeployment6d7d2c50": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -428,4 +432,4 @@
}
}
}
}
}
14 changes: 9 additions & 5 deletions test/fixtures/shortcuts/hookshot-passthrough-alarms.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentbdbc0f16"
"Ref": "PassDeployment6d7d2c50"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentbdbc0f16": {
"PassDeployment6d7d2c50": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -412,4 +416,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading