Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test-iac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
strategy:
matrix:
stack:
- m47-workshop-2-0-net-apigateway-production-stack
- m47-cdk-intro-workshop-apigateway-production-stack

steps:
- name: πŸš€ ♂️ Checkout
Expand Down Expand Up @@ -93,10 +93,10 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "eu-west-1"

- name: πŸ”§ Prepare CDK environment
run: |
#- name: πŸ”§ Prepare CDK environment
# run: |
# Run the script to remove profile from cdk.json for CI/CD environment
bash ./scripts/remove_cdk_profile.sh
# bash ./scripts/remove_cdk_profile.sh

- name: πŸ“ Create frontend 'dist' directory
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Use AWS Lambda Python base image with RIC
# Use AWS Lambda Python base image without RIC
FROM public.ecr.aws/lambda/python:3.9

EXPOSE 8000

# Set environment variables for Lambda
ENV PYTHONPATH=${LAMBDA_TASK_ROOT}
ENV DEPLOYMENT_TYPE=lambda
ENV IMAGE_TYPE=custom
ENV RUNTIME_INTERFACE=ric
ENV IMAGE_TYPE=public.ecr.aws/lambda/python:3.9
ENV RUNTIME_INTERFACE=direct

# Copy requirements and install dependencies
COPY requirements.txt ${LAMBDA_TASK_ROOT}
COPY workshop/src/apps/FastApiApp/requirements.txt ${LAMBDA_TASK_ROOT}
RUN pip install --no-cache-dir -r requirements.txt

# Copy application files
COPY main.py ${LAMBDA_TASK_ROOT}
COPY lambda_handler.py ${LAMBDA_TASK_ROOT}
COPY workshop/src/apps/FastApiApp ${LAMBDA_TASK_ROOT}
Comment thread
macalbert marked this conversation as resolved.

# Set the CMD to your handler
CMD ["lambda_handler.lambda_handler"]
24 changes: 0 additions & 24 deletions workshop/src/apps/FastApiApp/Dockerfile.public

This file was deleted.

30 changes: 30 additions & 0 deletions workshop/src/apps/FastApiApp/Dockerfile.ric
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Using public Python slim image with RIC
FROM python:3.9-slim

# Set working directory
ARG LAMBDA_TASK_ROOT="/var/task"
RUN mkdir -p ${LAMBDA_TASK_ROOT}
WORKDIR ${LAMBDA_TASK_ROOT}

# Set environment variables
ENV PYTHONPATH=${LAMBDA_TASK_ROOT}
ENV DEPLOYMENT_TYPE=lambda
ENV IMAGE_TYPE=python:3.9-slim
ENV RUNTIME_INTERFACE=ric

# Expose port
EXPOSE 8000

COPY workshop/src/apps/FastApiApp/requirements.txt .

# Install the function's dependencies
RUN pip install awslambdaric
RUN pip install --no-cache-dir -r requirements.txt

COPY workshop/src/apps/FastApiApp .

# Set runtime interface client as default command for the container runtime
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]

# Pass the name of the function handler as an argument to the runtime
CMD ["lambda_handler.lambda_handler"]
30 changes: 23 additions & 7 deletions workshop/src/apps/FastApiApp/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import uvicorn
import os

# Response models for better Swagger documentation
class MessageResponse(BaseModel):
message: str
deployment: str

class HealthResponse(BaseModel):
status: str
service: str

class EchoResponse(BaseModel):
echoed: dict
received_at: str

app = FastAPI(
title="CDK Workshop FastAPI",
description="Demo API for CDK Workshop",
version="1.0.0"
description="Demo API for CDK Workshop - A comprehensive API showcasing different deployment strategies",
version="1.0.0",
docs_url="/swagger", # Swagger UI endpoint
redoc_url="/redoc" # ReDoc endpoint
)

# Configure CORS
Expand All @@ -18,15 +34,15 @@
allow_headers=["*"],
)

@app.get("/")
@app.get("/", response_model=MessageResponse, summary="Root endpoint", description="Returns a welcome message")
async def root():
return {"message": "Hello from FastAPI!", "deployment": "workshop"}

@app.get("/health")
@app.get("/health", response_model=HealthResponse, summary="Health check", description="Returns the health status of the service")
async def health_check():
return {"status": "healthy", "service": "fastapi-workshop"}

@app.get("/info")
@app.get("/info", summary="Service information", description="Returns detailed information about the service and deployment")
async def get_info():
return {
"runtime": "FastAPI",
Expand All @@ -38,10 +54,10 @@ async def get_info():
}
}

@app.post("/echo")
@app.post("/echo", response_model=EchoResponse, summary="Echo data", description="Echoes back the provided JSON data")
async def echo_data(data: dict):
return {"echoed": data, "received_at": "fastapi-endpoint"}

# For local development
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="0.0.0.0", port=80)
Comment thread
macalbert marked this conversation as resolved.
9 changes: 8 additions & 1 deletion workshop/src/iac/bin/iac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ const rootPath = path.join(process.cwd(), "../../../");

const dockerfileApi = path.join(
rootPath,
"workshop/src/apps/Minimal.Api/Dockerfile",
// Custom dotnet with package RIC
// "workshop/src/apps/Minimal.Api/Dockerfile"

// Python with public ECR image
// "workshop/src/apps/FastApiApp/Dockerfile"

// Python with custom image
"workshop/src/apps/FastApiApp/Dockerfile.ric"
);

const modulesPath: ModulesPathProps = {
Expand Down