Created
December 12, 2024 19:55
-
-
Save xtreme-sameer-vohra/88cf1e6d309c6134e50bf7628c280a57 to your computer and use it in GitHub Desktop.
Generate CloudWatch Log payload to test AWS Lambda for New Relic
This file contains hidden or 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
import json | |
import gzip | |
import base64 | |
payload = { | |
"logGroup": "/ecs/SOME_APP", | |
"logStream": "ecs/SOME_APP/SOME_OTHER_ID", | |
"logEvents": [ | |
{ | |
"message": "THIS IS A TEST MESSAGE", | |
"timestamp": 1734030778338, | |
"ingestionTime": 1734030778339 | |
} | |
] | |
} | |
# Convert payload to JSON string | |
payload_str = json.dumps(payload) | |
# Compress the JSON string using gzip | |
compressed_payload = gzip.compress(payload_str.encode('utf-8')) | |
# Encode the compressed payload in Base64 | |
encoded_payload = base64.b64encode(compressed_payload).decode('utf-8') | |
aws_payload = { | |
"awslogs": { | |
"data": encoded_payload | |
} | |
} | |
print(json.dumps(aws_payload, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment