I'm trying to provision a lambda on a free localstack instance. As such, I cannot build the lambda as an image and push it into localstack's ECR because ECR is a paid resource. So I'm taking the approach of using "sam" and having that do all the heavy lifting for me.
My docker-compose is running:
my-service-localstack:
container_name: my-service-localstack
build:
context: .
dockerfile: localstack/Dockerfile
ports:
- 4576:4566
networks:
- blah
environment:
- AWS_DEFAULT_REGION=us-east-1
- AWS_ACCESS_KEY_ID=test
- AWS_SECRET_ACCESS_KEY=test
- LAMBDA_EXECUTOR=local
- LAMBDA_DOCKER_NETWORK=blah
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- ./localstack/init-localstack.sh:/etc/localstack/init/ready.d/init-localstack.sh
- ./localstack/template.localstack.yml:/var/lib/localstack/template.localstack.yml
- ./src/AWS.Lambdas/ConfigAggregator-lambda/src:/src/AWS.Lambdas/ConfigAggregator-lambda/src
- /var/run/docker.sock:/var/run/docker.sock
That runs my Dockerfile which installs the .Net 8 SDK into the latest localstack image as well as the sam-cli and awscli.
# Start from the official LocalStack image
FROM localstack/localstack:latest
# Install AWS SAM CLI and awscli-local
RUN pip install --no-cache-dir aws-sam-cli awscli-local
# Install .NET SDK (example for .NET 8)
RUN apt-get update && \
apt-get install -y wget apt-transport-https && \
wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
dpkg -i packages-microsoft-prod.deb && \
apt-get update && \
apt-get install -y dotnet-sdk-8.0 && \
rm -rf /var/lib/apt/lists/*
ENV PATH="$PATH:/root/.dotnet/tools"
Next we have the localstack startup script which runs as the container is starting up since we copied it into the container in our docker compose:
#!/bin/bash
set -euxo pipefail
set -e
# Point AWS CLI calls to LocalStack
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_DEFAULT_REGION=us-east-1
export AWS_ENDPOINT_URL=http://localhost:4566
# Build the Lambda image from your Dockerfile
sam build --template /var/lib/localstack/template.localstack.yml
# Deploy into LocalStack, pushing the image into LocalStack's ECR
sam deploy \
--stack-name my-service\
--resolve-s3 \
--region us-east-1 \
--capabilities CAPABILITY_IAM \
--no-confirm-changeset \
--no-fail-on-empty-changeset
Finally, we provision our localstack resources themselves in a cloud formation template that we told sam above to build:
---
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
Description: >
Creates/Manages an my-service stack
Metadata:
cfn-lint:
config:
ignore_checks:
- W3002
- I3042
Parameters:
S3ConfigBucketName:
Type: String
Default: 'my-service-config-aggregator'
Resources:
ConfigAggregatorBucket:
Type: AWS::S3::Bucket
DependsOn:
- ConfigAggregatorLambda
- ConfigAggregatorLambdaPermission
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
BucketName: !Ref S3ConfigBucketName
NotificationConfiguration:
LambdaConfigurations:
- Event: s3:ObjectCreated:Put
Function: !GetAtt ConfigAggregatorLambda.Arn
ConfigAggregatorLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: ConfigAggregator-lambda
Runtime: dotnet8
Handler: ConfigAggregator_lambda::ConfigAggregator_lambda.Function::FunctionHandler
CodeUri: /src/AWS.Lambdas/ConfigAggregator-lambda/src
MemorySize: 512
Timeout: 30
Environment:
Variables:
REFRESH_FUNCTION_NAME: ''
CONFIG_BUCKET_NAME: !Ref S3ConfigBucketName
ConfigAggregatorLambdaPermission:
Type: AWS::Lambda::Permission
DependsOn:
- ConfigAggregatorBucket
- ConfigAggregatorLambda
Properties:
FunctionName: !Ref ConfigAggregatorLambda
Action: lambda:InvokeFunction
Principal: s3.amazonaws.com
SourceArn: !GetAtt ConfigAggregatorBucket.Arn
All of that executes fine, but when the resources go to provision, I get the following error in my localstack container in Docker Desktop:
CREATE_FAILED AWS::Lambda::Function ConfigAggregatorLambda An error occurred (InvalidParameterValueException) when calling the CreateFunction operation: Value dotnet8 at 'runtime' failed to satisfy constraint: Member must satisfy enum value set: [java17, provided, nodejs16.x, nodejs14.x, ruby2.7, python3.10, java11, python3.11, dotnet6, go1.x, nodejs18.x, provided.al2, java8, java8.al2, ruby3.2, python3.7, python3.8, python3.9] or be a valid ARN
Looking at localstack's documentation: https://docs.localstack.cloud/aws/services/lambda/#special-tools
They note that they:
matching AWS parity (i.e., excluding deprecated runtimes)
AWS supports: https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtimes-supported
Note that dotnet6 is deprecated and dotnet8 is supported.
Any ideas where the disconnect is? I can't seem to find much information on which runtimes localstack supports in the free account but I can see that they added official support for dotnet8 here: https://github.com/localstack/localstack/pull/10300
Any advice is appreciated.