-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreTrafficHook.py
34 lines (28 loc) · 972 Bytes
/
preTrafficHook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import boto3
import os
def lambda_handler(event, context):
deploymentId = event["DeploymentId"]
lifecycleEventHookExecutionId = event["LifecycleEventHookExecutionId"]
client = boto3.client("lambda", region_name="us-east-2")
codeclient = boto3.client("codedeploy")
payload = {"message": "Hi, you have been invoked."}
funname = os.environ["NewVersion"]
status = "Failed"
resp = client.invoke(
FunctionName=funname,
InvocationType="RequestResponse",
Payload=json.dumps(payload),
)
dic = json.loads(resp["Payload"].read().decode("utf-8"))
dic = json.loads(dic["body"])
# print(dic["status"]==200)
if dic["status"] == 200:
status = "Succeeded"
else:
status = "Failed"
_ = codeclient.put_lifecycle_event_hook_execution_status(
deploymentId=deploymentId,
lifecycleEventHookExecutionId=lifecycleEventHookExecutionId,
status=status,
)