1
+ // @ts -check
1
2
'use strict' ;
2
3
3
4
const aws = require ( 'aws-sdk' ) ;
4
5
const codedeploy = new aws . CodeDeploy ( { apiVersion : '2014-10-06' } ) ;
5
6
6
- exports . handler = ( event , context , callback ) => {
7
+ exports . handler = async ( event , context , callback ) => {
7
8
8
- console . log ( "Entering PreTraffic Hook!" ) ;
9
- console . log ( JSON . stringify ( event ) ) ;
10
-
11
- //Read the DeploymentId from the event payload.
12
- var deploymentId = event . DeploymentId ;
13
- console . log ( deploymentId ) ;
9
+ console . log ( "Entering PreTraffic Hook!" ) ;
10
+ console . log ( JSON . stringify ( event ) ) ;
11
+
12
+ //Read the DeploymentId from the event payload.
13
+ let deploymentId = event . DeploymentId ;
14
+ console . log ( "deploymentId=" + deploymentId ) ;
14
15
15
16
//Read the LifecycleEventHookExecutionId from the event payload
16
- var lifecycleEventHookExecutionId = event . LifecycleEventHookExecutionId ;
17
- console . log ( lifecycleEventHookExecutionId ) ;
18
-
19
- /*
20
- [Perform validation or prewarming steps here]
21
- */
22
-
23
- // Prepare the validation test results with the deploymentId and
17
+ let lifecycleEventHookExecutionId = event . LifecycleEventHookExecutionId ;
18
+ console . log ( "lifecycleEventHookExecutionId=" + lifecycleEventHookExecutionId ) ;
19
+
20
+ /*
21
+ [Perform validation or prewarming steps here]
22
+ */
23
+
24
+ // Prepare the validation test results with the deploymentId and
24
25
// the lifecycleEventHookExecutionId for AWS CodeDeploy.
25
- var params = {
26
+ let params = {
26
27
deploymentId : deploymentId ,
27
28
lifecycleEventHookExecutionId : lifecycleEventHookExecutionId ,
28
29
status : 'Succeeded' // status can be 'Succeeded' or 'Failed'
29
30
} ;
30
-
31
- // Pass AWS CodeDeploy the prepared validation test results.
32
- codedeploy . putLifecycleEventHookExecutionStatus ( params , function ( err , data ) {
33
- if ( err ) {
34
- // Validation failed.
35
- console . log ( 'Validation test failed' ) ;
36
- console . log ( err ) ;
37
- console . log ( data ) ;
38
- callback ( 'Validation test failed' ) ;
39
- } else {
40
- // Validation succeeded.
41
- console . log ( 'Validation test succeeded' ) ;
42
- callback ( null , 'Validation test succeeded' ) ;
43
- }
44
- } ) ;
31
+
32
+ try {
33
+ await codedeploy . putLifecycleEventHookExecutionStatus ( params ) . promise ( ) ;
34
+ console . log ( "putLifecycleEventHookExecutionStatus done. executionStatus=[" + params . status + "]" ) ;
35
+ return 'Validation test succeeded'
36
+ }
37
+ catch ( err ) {
38
+ console . log ( "putLifecycleEventHookExecutionStatus ERROR: " + err ) ;
39
+ throw new Error ( 'Validation test failed' )
40
+ }
41
+
45
42
}
46
43
47
- // 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
44
+ // 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
0 commit comments