Skip to content

Instantly share code, notes, and snippets.

@ystoneman
Created February 21, 2022 21:35
Show Gist options
  • Save ystoneman/27aea8c6396ecd3d1dcc5fc7dc2ef0be to your computer and use it in GitHub Desktop.
Save ystoneman/27aea8c6396ecd3d1dcc5fc7dc2ef0be to your computer and use it in GitHub Desktop.
Lambda function that puts a hello-world log message into CloudWatch Logs, just to test connectivity and permissions.
import json
import boto3
import time
def lambda_handler(event, context):
LOG_GROUP='awesome-logs'
LOG_STREAM='test'
logs = boto3.client('logs')
logs.create_log_stream(logGroupName=LOG_GROUP, logStreamName=LOG_STREAM)
timestamp = int(round(time.time() * 1000))
response = logs.put_log_events(
logGroupName=LOG_GROUP,
logStreamName=LOG_STREAM,
logEvents=[
{
'timestamp': timestamp,
'message': 'Hello world, here is our first log message!'
}
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment