Skip to content

Commit b004077

Browse files
committed
Lambda needs to check into codepipeline, so we need IAM and python changes
1 parent b7009fb commit b004077

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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

5869
resource "aws_iam_role_policy" "this" {

rolling-restart.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
except:
1818
raise
1919

20+
try:
21+
codepipeline = boto3.client(
22+
'codepipeline'
23+
)
2024

2125
def 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

7087
def 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')

variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,9 @@ variable "asg_name" {
2727
variable "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
}

0 commit comments

Comments
 (0)