Patched AWS SDKs for Lambdas
The Lambda runtime in LocalStack uses patched AWS SDKs, which are configured to target the local APIs instead of the real AWS. This behavior is enabled by default for most Lambda runtimes when using LocalStack Pro.
Assuming you had a Python Lambda handler that attempts to list all S3 buckets. In the past, you had to manually configure the
endpoint_url parameter on the boto3 client (and potentially use environment switches for dev/prod in your test code):
import boto3 def handler(event, context): client = boto3.client("s3", endpoint_url="http://localhost:4566") print(client.list_buckets())
With the patched AWS SDKs, it now becomes possible to deploy your unmodified production code to LocalStack, simply creating a boto3 client with default settings. The invocations of the boto3 client will be automatically forwarded to the local APIs:
import boto3 def handler(event, context): client = boto3.client("s3") print(client.list_buckets())
This feature works by patching the AWS SDKs in the docker images, which provide the execution environment for Lambdas within LocalStack.
The main advantage of this mode is, that no DNS magic is involved, and SSL certificate checks do not have to be disabled.
If you want to disable this behavior, and use the DNS server to resolve the endpoints for AWS, you can disable this behavior by using:
Currently, LocalStack supports patching the SDKs for the following runtimes:
- Python (using boto3)
Also, these patched SDKs are only available in the following Lambda execution modes:
This feature is currently not supported for custom Lambda container images.