Skip to content

Commit

Permalink
fix(cfnspec): aws-sam deployment preferences hooks (#19732)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
calabrla committed Apr 12, 2022
1 parent 7867dc4 commit a205734
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/@aws-cdk/aws-sam/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,29 @@ test("correctly chooses a string array from the type unions of the 'policies' pr
Policies: ['AWSLambdaExecute'],
});
});

test('has the correct deployment preference hooks structure', () => {
const stack = new cdk.Stack();

new sam.CfnFunction(stack, 'MyFunction', {
deploymentPreference: {
enabled: true,
type: 'AllAtOnce',
hooks: {
preTraffic: 'pre-traffic-hook-arn',
postTraffic: 'post-traffic-hook-arn',
},
},
});

Template.fromStack(stack).hasResourceProperties('AWS::Serverless::Function', {
DeploymentPreference: {
Enabled: true,
Type: 'AllAtOnce',
Hooks: {
PreTraffic: 'pre-traffic-hook-arn',
PostTraffic: 'post-traffic-hook-arn',
},
},
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"PropertyTypes": {
"patch": {
"description": "Replace AWS::Serverless::Function.DeploymentPreference#Hooks",
"operations": [
{
"op": "replace",
"path": "/AWS::Serverless::Function.DeploymentPreference/Properties/Hooks",
"value": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object",
"Type": "Hooks",
"Required": false,
"UpdateType": "Immutable"
}
},
{
"op": "add",
"path": "/AWS::Serverless::Function.Hooks",
"value": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/docs/safe_lambda_deployments.rst",
"Properties": {
"PreTraffic": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object",
"Required": false,
"PrimitiveType": "String",
"UpdateType": "Immutable"
},
"PostTraffic": {
"Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object",
"Required": false,
"PrimitiveType": "String",
"UpdateType": "Immutable"
}
}
}
}
]
}
}
}

0 comments on commit a205734

Please sign in to comment.