Skip to content

Commit

Permalink
Update versions, endpoint methods and docs endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
san99tiago committed Feb 26, 2024
1 parent 4a52492 commit de72dce
Show file tree
Hide file tree
Showing 7 changed files with 1,147 additions and 1,179 deletions.
2 changes: 1 addition & 1 deletion cdk.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"main_resources_name": "fastapi-lambda",
"tags": {
"Owner": "Santiago Garcia Arango",
"Source": "https://github.com/san99tiago/aws-cdk-fastapi-lambda",
"Source": "https://github.com/san99tiago/aws-fastapi-lambda",
"Usage": "Sample project to illustrate a quick easy FastAPI deployment on Lambda Functions"
}
}
31 changes: 15 additions & 16 deletions cdk/stacks/cdk_lambda_fastapi_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,14 @@ def create_lambda_layers(self):
dependencies of the Lambda Functions.
"""

# Layer for "LambdaPowerTools" (for logging, traces, observability, etc)
self.lambda_layer_powertools = aws_lambda.LayerVersion.from_layer_version_arn(
self,
id="LambdaLayer-Powertools",
layer_version_arn=f"arn:aws:lambda:{self.region}:017000801446:layer:AWSLambdaPowertoolsPythonV2:35",
)

# Layer for "FastAPI" and "Mangum" Adapter libraries
self.lambda_layer_fastapi = aws_lambda.LayerVersion(
self,
id="LambdaLayer-FastAPI",
code=aws_lambda.Code.from_asset("lambda-layers/fastapi/modules"),
compatible_runtimes=[
aws_lambda.Runtime.PYTHON_3_9,
aws_lambda.Runtime.PYTHON_3_10,
aws_lambda.Runtime.PYTHON_3_11,
aws_lambda.Runtime.PYTHON_3_12,
],
description="Lambda Layer for Python with <fastapi> library",
removal_policy=RemovalPolicy.DESTROY,
Expand All @@ -81,24 +74,23 @@ def create_lambda_functions(self):
self.lambda_fastapi: aws_lambda.Function = aws_lambda.Function(
self,
id="Lambda-FastAPI",
runtime=aws_lambda.Runtime.PYTHON_3_9,
runtime=aws_lambda.Runtime.PYTHON_3_12,
handler="api/main.handler",
code=aws_lambda.Code.from_asset(PATH_TO_LAMBDA_FUNCTION_FOLDER),
timeout=Duration.seconds(30),
timeout=Duration.seconds(20),
memory_size=128,
environment={
"ENVIRONMENT": self.deployment_environment,
"LOG_LEVEL": "DEBUG",
"STATE_MACHINE_ENABLED": "true",
},
layers=[
self.lambda_layer_powertools,
self.lambda_layer_fastapi,
],
)

# NOTE: If IAM-based based auth needed, update the "auth_type" to "AWS_IAM"
self.lambda_function_url = self.lambda_fastapi.add_function_url(
auth_type=aws_lambda.FunctionUrlAuthType.AWS_IAM,
auth_type=aws_lambda.FunctionUrlAuthType.NONE
)

def generate_cloudformation_outputs(self):
Expand All @@ -115,7 +107,14 @@ def generate_cloudformation_outputs(self):

CfnOutput(
self,
"LambdaFunctionUrl",
"LambdaFunctionRootUrl",
value=self.lambda_function_url.url,
description="Root URL to invoke Lambda Function",
)

CfnOutput(
self,
"LambdaFunctionDocsUrl",
value=self.lambda_function_url.url,
description="URL to invoke Lambda Function",
description="Documentation URL to invoke Lambda Function",
)
2 changes: 1 addition & 1 deletion lambda-layers/fastapi/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
all:
[ -d "modules/python" ] || pip install -r requirements.txt -t modules/python/
[ -d "modules/python" ] || pip install -r requirements.txt -t modules/python/ --platform manylinux2014_x86_64 --only-binary=:all:

clean:
rm -rf modules
2 changes: 1 addition & 1 deletion lambda-layers/fastapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fastapi==0.98.0
fastapi==0.109.0
mangum==0.17.0
Loading

0 comments on commit de72dce

Please sign in to comment.