Skip to content

Commit a205734

Browse files
authored
fix(cfnspec): aws-sam deployment preferences hooks (#19732)
Currently, the `AWS::Serverless::Function.DeploymentPreference.Hooks` property is defined as a list of strings in the cfnspec. However, it should be an object of `{ PreTraffic: '', PostTraffic: '' }` per the spec [here](https://github.com/aws/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object). I updated the tests in `@aws-cdk/aws-sam` to verify the structure. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7867dc4 commit a205734

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

packages/@aws-cdk/aws-sam/test/function.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,29 @@ test("correctly chooses a string array from the type unions of the 'policies' pr
2525
Policies: ['AWSLambdaExecute'],
2626
});
2727
});
28+
29+
test('has the correct deployment preference hooks structure', () => {
30+
const stack = new cdk.Stack();
31+
32+
new sam.CfnFunction(stack, 'MyFunction', {
33+
deploymentPreference: {
34+
enabled: true,
35+
type: 'AllAtOnce',
36+
hooks: {
37+
preTraffic: 'pre-traffic-hook-arn',
38+
postTraffic: 'post-traffic-hook-arn',
39+
},
40+
},
41+
});
42+
43+
Template.fromStack(stack).hasResourceProperties('AWS::Serverless::Function', {
44+
DeploymentPreference: {
45+
Enabled: true,
46+
Type: 'AllAtOnce',
47+
Hooks: {
48+
PreTraffic: 'pre-traffic-hook-arn',
49+
PostTraffic: 'post-traffic-hook-arn',
50+
},
51+
},
52+
});
53+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"PropertyTypes": {
3+
"patch": {
4+
"description": "Replace AWS::Serverless::Function.DeploymentPreference#Hooks",
5+
"operations": [
6+
{
7+
"op": "replace",
8+
"path": "/AWS::Serverless::Function.DeploymentPreference/Properties/Hooks",
9+
"value": {
10+
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object",
11+
"Type": "Hooks",
12+
"Required": false,
13+
"UpdateType": "Immutable"
14+
}
15+
},
16+
{
17+
"op": "add",
18+
"path": "/AWS::Serverless::Function.Hooks",
19+
"value": {
20+
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/docs/safe_lambda_deployments.rst",
21+
"Properties": {
22+
"PreTraffic": {
23+
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object",
24+
"Required": false,
25+
"PrimitiveType": "String",
26+
"UpdateType": "Immutable"
27+
},
28+
"PostTraffic": {
29+
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object",
30+
"Required": false,
31+
"PrimitiveType": "String",
32+
"UpdateType": "Immutable"
33+
}
34+
}
35+
}
36+
}
37+
]
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)