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

## 8.3.0

- Support a default value for cf.findInMap (Fn::FindInMap).

## 8.2.0

- Add `LogRetentionInDays` option to Lambda shortcuts
Expand Down
10 changes: 8 additions & 2 deletions lib/intrinsic.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ intrinsic.cidr = (ipBlock, count, cidrBits) => {
* key-value pairs.
* @param {string} attr - The second-level key name, which is set to one of the
* keys from the list assigned to key.
* @param {string} defaultValue - The value that will resolve to if the key and/or attr can not be found from the mapping map.
* This field is optional and requires AWS::LanguageExtensions to be defined in the template.
* @returns The value that is assigned to SecondLevelKey.
*/
intrinsic.findInMap = (mapping, key, attr) => {
return { 'Fn::FindInMap': [mapping, key, attr] };
intrinsic.findInMap = (mapping, key, attr, defaultValue) => {
const lookup = [mapping, key, attr];
if (defaultValue) {
lookup.push({ DefaultValue: defaultValue });
}
return { 'Fn::FindInMap': lookup };
};

/**
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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/cloudfriend",
"version": "8.2.0",
"version": "8.3.0",
"description": "Helper functions for assembling CloudFormation templates in JavaScript",
"main": "index.js",
"engines": {
Expand All @@ -11,6 +11,7 @@
"lint": "eslint index.js test lib bin cloudformation",
"lint:fix": "npm run lint -- --fix",
"test": "nyc tape test/*.test.js | tap-spec",
"test:update": "UPDATE=1 npm run test",
"coverage": "nyc --reporter html tape test/*.test.js && opener coverage/index.html",
"build-ci-template": "bin/build-template.js cloudformation/ci.template.js > cloudformation/ci.template.json",
"shortcuts-api-doc": "jsdoc2md lib/shortcuts/*.js > lib/shortcuts/api.md"
Expand Down
4 changes: 2 additions & 2 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": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -47,7 +47,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 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": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 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": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand Down Expand Up @@ -52,7 +52,7 @@
}
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 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": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-passthrough-logging.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/shortcuts/hookshot-passthrough.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "PassDeploymentac7cb6b9"
"Ref": "PassDeployment2a35d33e"
},
"StageName": "hookshot",
"RestApiId": {
Expand All @@ -43,7 +43,7 @@
]
}
},
"PassDeploymentac7cb6b9": {
"PassDeployment2a35d33e": {
"Type": "AWS::ApiGateway::Deployment",
"DependsOn": "PassMethod",
"Properties": {
Expand Down
37 changes: 28 additions & 9 deletions test/fixtures/shortcuts/lambda-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"Mappings": {},
"Conditions": {
"Always": {
"Fn::Equals": ["1", "1"]
"Fn::Equals": [
"1",
"1"
]
}
},
"Resources": {
Expand Down Expand Up @@ -49,7 +52,9 @@
"FunctionName": "my-function",
"Handler": "index.something",
"KmsKeyArn": "arn:aws:kms:us-east-1:123456789012:key/fake",
"Layers": ["arn:aws:fake:layer/abc"],
"Layers": [
"arn:aws:fake:layer/abc"
],
"MemorySize": 512,
"ReservedConcurrentExecutions": 10,
"Runtime": "nodejs18.x",
Expand All @@ -58,8 +63,12 @@
"Mode": "Active"
},
"VpcConfig": {
"SecurityGroupIds": ["sg-12345"],
"SubnetIds": ["fake"]
"SecurityGroupIds": [
"sg-12345"
],
"SubnetIds": [
"fake"
]
},
"Tags": [
{
Expand All @@ -68,7 +77,10 @@
}
],
"Role": {
"Fn::GetAtt": ["MyLambdaRole", "Arn"]
"Fn::GetAtt": [
"MyLambdaRole",
"Arn"
]
}
}
},
Expand All @@ -78,7 +90,9 @@
"Properties": {
"AlarmName": "my-alarm",
"AlarmDescription": "some alarm",
"AlarmActions": ["[email protected]"],
"AlarmActions": [
"[email protected]"
],
"Period": 120,
"EvaluationPeriods": 2,
"DatapointsToAlarm": 1,
Expand All @@ -87,7 +101,9 @@
"ComparisonOperator": "LessThanThreshold",
"TreatMissingData": "breaching",
"EvaluateLowSampleCountPercentile": "ignore",
"OKActions": ["[email protected]"],
"OKActions": [
"[email protected]"
],
"Namespace": "AWS/Lambda",
"Dimensions": [
{
Expand Down Expand Up @@ -118,7 +134,10 @@
"Effect": "Allow",
"Action": "logs:*",
"Resource": {
"Fn::GetAtt": ["MyLambdaLogs", "Arn"]
"Fn::GetAtt": [
"MyLambdaLogs",
"Arn"
]
}
}
]
Expand Down Expand Up @@ -161,4 +180,4 @@
}
},
"Outputs": {}
}
}
16 changes: 8 additions & 8 deletions test/fixtures/shortcuts/stream-lambda-no-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,21 @@
"Properties": {
"BatchSize": 10000,
"MaximumBatchingWindowInSeconds": 300,
"Enabled": false,
"EventSourceArn": "arn:aws:kinesis:us-east-1:123456789012:stream/fake",
"FunctionName": {
"Ref": "MyLambda"
},
"StartingPosition": "TRIM_HORIZON",
"FilterCriteria": {
"Filters": [
{
"Pattern": "{\"eventName\":[\"INSERT\",\"MODIFY\"]}"
}
]
},
"Enabled": false,
"EventSourceArn": "arn:aws:kinesis:us-east-1:123456789012:stream/fake",
"FunctionName": {
"Ref": "MyLambda"
},
"StartingPosition": "TRIM_HORIZON"
}
}
}
},
"Outputs": {}
}
}
1 change: 1 addition & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('intrinsic functions', (assert) => {
assert.deepEqual(cloudfriend.base64('secret'), { 'Fn::Base64': 'secret' }, 'base64');
assert.deepEqual(cloudfriend.cidr('ipBlock', 1, 2), { 'Fn::Cidr': ['ipBlock', 1, 2] }, 'cidr');
assert.deepEqual(cloudfriend.findInMap('mapping', 'key', 'value'), { 'Fn::FindInMap': ['mapping', 'key', 'value'] }, 'lookup');
assert.deepEqual(cloudfriend.findInMap('mapping', 'key', 'value', 'hello-world'), { 'Fn::FindInMap': ['mapping', 'key', 'value', { DefaultValue: 'hello-world' }] }, 'lookup with default value');
assert.deepEqual(
cloudfriend.forEach('somethings', 'topic', ['abra', 'cadabra'], 'magic', {
Type: 'AWS::SNS::Topic',
Expand Down