/bootcamp-demo-hello-cors.py Secret
Created
January 2, 2023 02:50
Star
You must be signed in to star a gist
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
import boto3 | |
import os | |
from aws_lambda_powertools import Logger, Tracer | |
from aws_lambda_powertools.logging import correlation_paths | |
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, CORSConfig | |
tracer = Tracer() | |
logger = Logger() | |
cors_config = CORSConfig() | |
app = APIGatewayRestResolver(cors=cors_config) | |
@app.get("/hello/<name>") | |
@tracer.capture_method | |
def get_hello_universe(name): | |
if name == "michael": | |
name = "michael, go away!" | |
return {"message": f"hello {name}"} | |
# You can continue to use other utilities just as before | |
@logger.inject_lambda_context(log_event=True, correlation_id_path=correlation_paths.API_GATEWAY_REST) | |
@tracer.capture_lambda_handler | |
def lambda_handler(event, context): | |
return app.resolve(event, context) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment