Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example [lambda_safe_deployments] use nodejs8.10 for the PreTraffic hook #605

Merged
merged 2 commits into from
May 2, 2019
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
61 changes: 29 additions & 32 deletions examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
// @ts-check
'use strict';

const aws = require('aws-sdk');
const codedeploy = new aws.CodeDeploy({apiVersion: '2014-10-06'});

exports.handler = (event, context, callback) => {
exports.handler = async (event, context, callback) => {

console.log("Entering PreTraffic Hook!");
console.log(JSON.stringify(event));
//Read the DeploymentId from the event payload.
var deploymentId = event.DeploymentId;
console.log(deploymentId);
console.log("Entering PreTraffic Hook!");
console.log(JSON.stringify(event));

//Read the DeploymentId from the event payload.
let deploymentId = event.DeploymentId;
console.log("deploymentId=" + deploymentId);

//Read the LifecycleEventHookExecutionId from the event payload
var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
console.log(lifecycleEventHookExecutionId);

/*
[Perform validation or prewarming steps here]
*/
// Prepare the validation test results with the deploymentId and
let lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
console.log("lifecycleEventHookExecutionId=" + lifecycleEventHookExecutionId);

/*
[Perform validation or prewarming steps here]
*/

// Prepare the validation test results with the deploymentId and
// the lifecycleEventHookExecutionId for AWS CodeDeploy.
var params = {
let params = {
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Succeeded' // status can be 'Succeeded' or 'Failed'
};

// Pass AWS CodeDeploy the prepared validation test results.
codedeploy.putLifecycleEventHookExecutionStatus(params, function(err, data) {
if (err) {
// Validation failed.
console.log('Validation test failed');
console.log(err);
console.log(data);
callback('Validation test failed');
} else {
// Validation succeeded.
console.log('Validation test succeeded');
callback(null, 'Validation test succeeded');
}
});

try {
await codedeploy.putLifecycleEventHookExecutionStatus(params).promise();
console.log("putLifecycleEventHookExecutionStatus done. executionStatus=[" + params.status + "]");
sullis marked this conversation as resolved.
Show resolved Hide resolved
return 'Validation test succeeded'
}
catch (err) {
console.log("putLifecycleEventHookExecutionStatus ERROR: " + err);
throw new Error('Validation test failed')
}

}

// See more: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#reference-appspec-file-structure-hooks-section-structure-lambda-sample-function
// See more: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#reference-appspec-file-structure-hooks-section-structure-lambda-sample-function
5 changes: 3 additions & 2 deletions examples/2016-10-31/lambda_safe_deployments/src/safeTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';


exports.handler = (event, context, callback) => {
exports.handler = async (event, context, callback) => {

console.log("Function loaded! " + context.functionName + ":" + context.functionVersion);

callback(null, "Success");
}
}
6 changes: 3 additions & 3 deletions examples/2016-10-31/lambda_safe_deployments/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Properties:
Handler: safeTest.handler
CodeUri: src/
Runtime: nodejs6.10
Runtime: nodejs8.10
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery1Minute
Expand All @@ -35,10 +35,10 @@ Resources:
Action:
- "lambda:InvokeFunction"
Resource: !Ref safeTest.Version
Runtime: nodejs6.10
Runtime: nodejs8.10
FunctionName: 'CodeDeployHook_preTrafficHook'
DeploymentPreference:
Enabled: false
Environment:
Variables:
CurrentVersion: !Ref safeTest.Version
CurrentVersion: !Ref safeTest.Version