1234567891011121314151617181920212223242526272829303132333435363738 |
- #! /usr/bin/env python3
- #
- # Sample code to store something in redis
- import base64
- import json
- import os
- def server_error(errorstring):
- return {"statusCode": 200, "isBase64Encoded": False, "body": errorstring}
- def lambda_handler(event, context):
- redis_endpoint = os.environ["REDIS_ENDPOINT"]
- try:
- params = event.get("body", {})
- if event.get("isBase64Encoded", False):
- params = base64.b64decode(body).decode()
- params = json.loads(body)
- except Exception as e:
- return server_error(str(e))
- # `params` should now be a valid structure.
- return {
- "statusCode": 200,
- "isBase64Encoded": False,
- "body": json.dumps({"asked_to_store": body}, default=str),
- }
- def main():
- print("No CLI support.")
- if __name__ == "__main__":
- main()
|