Skip to content
Clean Lambda Function
Lean Mean Clean Apps

Five templates, one brand, one search box. Everything in the docs is in here, including the bits we hoped you'd skim.

Try one of these

Results say which template they came from, so you won't end up reading about Lambda when you wanted GraphQL. Again.

Deploy to AWS

The functions deploy as one container image and one CloudFormation stack. src/Presentation/serverless.template has a Lambda function for each handler method, and Lambda Annotations keeps it in step every time you build. The Amazon.Lambda.Tools CLI builds the image, pushes it to Amazon ECR and creates or updates the stack in one go.

  1. Install the CLI.

    Terminal window
    dotnet tool install -g Amazon.Lambda.Tools
  2. Fill in src/Presentation/aws-lambda-tools-defaults.json. The template leaves profile, region and stack-name empty on purpose. We don’t know where you live.

    {
    "profile": "default",
    "region": "ap-southeast-2",
    "configuration": "Release",
    "template": "serverless.template",
    "stack-name": "worksonmymachine-movies"
    }
  3. Deploy.

    Terminal window
    dotnet lambda deploy-serverless --project-location ./src/Presentation

    Each function gets the basic execution role, so it can write to CloudWatch Logs and nothing else.

  4. Invoke it for real. CloudFormation names each function after the stack and the resource, so look the name up first.

    Terminal window
    FUNCTION=$(aws cloudformation describe-stack-resource --stack-name worksonmymachine-movies \
    --logical-resource-id GetMovies --query StackResourceDetail.PhysicalResourceId --output text)
    aws lambda invoke --function-name "$FUNCTION" \
    --cli-binary-format raw-in-base64-out --payload '{"limit":5}' response.json

    Or call it over HTTP. The stack’s ApiUrl output is the API Gateway address.

    Terminal window
    API_URL=$(aws cloudformation describe-stacks --stack-name worksonmymachine-movies \
    --query "Stacks[0].Outputs[?OutputKey=='ApiUrl'].OutputValue" --output text)
    curl "${API_URL}movies?limit=5"

Each Lambda function runs one handler method. The stack already has GetMovies, GetAuthors and GetReviews, plus their HTTP twins HttpGetMovies, HttpGetAuthors and HttpGetReviews, all running the same image with a different command. They share the code but scale and bill separately. Add a method with [LambdaFunction], build, and the next deploy adds its function too.

Logs land in CloudWatch Logs whatever you do. For traces and metrics too, give the function a collector and set OTEL_EXPORTER_OTLP_ENDPOINT to it. Container images can’t use Lambda layers, so either build the AWS Distro for OpenTelemetry collector extension into the image, or run a collector as a gateway the function can reach. The collector then decides where everything goes, X-Ray included, and changing your mind never means touching the function. otel-collector.yaml is a good starting point for its configuration.

Setting Template default Why you might change it
MemorySize on [LambdaFunction] 256 MB Lambda gives you CPU in proportion to memory, so more memory often means a faster cold start
Timeout on [LambdaFunction] 30 seconds The handler stops its work when the invocation is about to run out of time, so set this to what your callers will wait for