-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlambda.py
More file actions
26 lines (21 loc) · 903 Bytes
/
lambda.py
File metadata and controls
26 lines (21 loc) · 903 Bytes
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
import os
import logging
import boto3
import json
logger = logging.getLogger(__name__)
def handler(event, context):
try:
endpoint_url = None
# Automatic boto instrumentation is a pro feature https://docs.localstack.cloud/user-guide/tools/transparent-endpoint-injection/
# we'll do this manually here
if os.environ.get("AWS_ENDPOINT_URL"):
endpoint_url = os.environ["AWS_ENDPOINT_URL"]
kinesis = boto3.client(
"kinesis", endpoint_url=endpoint_url, region_name=os.environ["AWS_REGION"], verify=False
)
stream_name = os.environ['STREAM_NAME']
kinesis.put_record(StreamName=stream_name, Data=json.dumps(event), PartitionKey="1")
logger.info("Put record in stream %s.", stream_name)
except Exception:
logger.exception("Sending record to kinesis failed.")
return {"body": "Hello World!"}