Last active
December 13, 2019 10:53
-
-
Save ottokruse/28b8642e262a3b55cd00b232c11c30d5 to your computer and use it in GitHub Desktop.
A better cfn-response for Python3, only depends on stdlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.request import Request, urlopen | |
import json | |
class CfnResponse: | |
SUCCESS = "SUCCESS" | |
FAILED = "FAILED" | |
@staticmethod | |
def send( | |
event, | |
context, | |
response_status, | |
reason="See CloudWatch Logs", | |
response_data=None, | |
physical_resource_id=None, | |
): | |
response = { | |
"Status": response_status, | |
"Reason": reason, | |
"PhysicalResourceId": physical_resource_id or context.log_stream_name, | |
"StackId": event["StackId"], | |
"RequestId": event["RequestId"], | |
"LogicalResourceId": event["LogicalResourceId"], | |
"Data": response_data or {}, | |
} | |
urlopen( | |
Request( | |
event["ResponseURL"], | |
data=json.dumps(response).encode(), | |
headers={"content-type": ""}, | |
method="PUT", | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment