Lambda container cannot reach LocalStack S3 during sam local invoke
criticalConnection ManagementUpdated May 25, 2024(via Exa)
Technologies:
How to detect:
When invoking Lambda functions locally with 'sam local invoke', the Lambda container cannot connect to LocalStack S3 at localhost:4566 or s3.localhost.localstack.cloud:4566, resulting in connection refused errors. The hostname resolves to 127.0.0.1 inside the SAM container, which cannot reach LocalStack running in a separate container.
Recommended action:
Configure the Lambda S3 client endpoint to 'http://host.docker.internal:4566' instead of 'localhost:4566' or 's3.localhost.localstack.cloud:4566'. Alternatively, use 'samlocal' wrapper instead of 'sam local', or use 'sam remote invoke' (without 'local' keyword) with a LocalStack profile that has endpoint_url configured.