File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,17 @@ data "aws_iam_policy_document" "lambda_policy_doc" {
5353 " *"
5454 ]
5555 }
56+ statement {
57+ actions = [
58+ " codepipeline:PutJobSuccessResult" ,
59+ " codepipeline:PutJobFailureResult"
60+ ]
61+
62+ resources = [
63+ var . codepipeline_arn
64+ ]
65+ }
66+
5667}
5768
5869resource "aws_iam_role_policy" "this" {
Original file line number Diff line number Diff line change 1717except :
1818 raise
1919
20+ try :
21+ codepipeline = boto3 .client (
22+ 'codepipeline'
23+ )
2024
2125def getAsg (name ):
2226 try :
@@ -66,6 +70,19 @@ def replaceInstances(idList):
6670 while not isAsgHealthy (getAsg (ASGNAME )) and len (getAsgInstances (getAsg (ASGNAME ))) == targetNum :
6771 time .sleep (1 )
6872
73+ def putJobSuccess (event )
74+ response = codepipeline .put_job_success_result (
75+ jobId = event ['CodePipeline.job' ].id
76+ )
77+
78+ def putJobFailure (event , message )
79+ response = codepipeline .put_job_failure_result (
80+ jobId = event ['CodePipeline.job' ].id ,
81+ failureDetails = {
82+ 'type' : 'JobFailed' ,
83+ 'message' : message
84+ }
85+ )
6986
7087def handler (event , context ):
7188 logger .debug ('## ENVIRONMENT VARIABLES' )
@@ -82,6 +99,7 @@ def handler(event, context):
8299 logger .info (
83100 'Done! All instances have been replaced and are marked as healthy'
84101 )
102+ putJobSuccess (event )
85103 return {
86104 'statusCode' : 200 ,
87105 'body' : json .dumps ('Done! All instances have been replaced and are marked as healthy' )
Original file line number Diff line number Diff line change @@ -27,5 +27,9 @@ variable "asg_name" {
2727variable "tags" {
2828 type = map
2929 description = " Map of tags that should be added to stuff"
30+ }
3031
32+ variable "codepipeline_arn" {
33+ type = string
34+ description = " ARN of the codepipeline we are interacting with. * will work for all"
3135}
You can’t perform that action at this time.
0 commit comments