aws / aws/aws-sam-cli

sam local start-api cannot access localstack

Open
#4,861 4 comments 0 reactions 0 assignees View on GitHub
area/docker-lambda area/local/start-api type/question
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

I am getting `The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.`

My command:
`sam local start-api --env-vars local_env.json -t ./cdk.out/ApiStack.template.json --region eu-central-1
--docker-network "" --force-image-build`

When I make a request that runs in my lambda, it fails to even reach localstack (no interaction logged on their side).

I ran the lambda code in its own docker container and my code works, even through docker so the issue must be with sam I guess.
So I don't get what I am doing wrong.

sam version: `1.76.0'
LOCALSTACK_ENDPOINT=""

---

The code I use to connect to the bucket:
```rust
let config = aws_config::load_from_env().await;
// local development
let mut config = aws_sdk_s3::config::Builder::from(&config);
if let Ok(endpoint) = env::var("LOCALSTACK_ENDPOINT") {
let ep = s3::Endpoint::immutable(endpoint.parse::().unwrap());
let cred = s3::Credentials::new("access", "secret", None, None, "custom");
// Region is not used but is required by the SDK's API
let region = s3::Region::new("eu-central-1");
config = config
.endpoint_resolver(ep)
.region(region)
.credentials_provider(cred);
}
let client = s3::Client::from_conf(config.build());
```

local_env.json
```json
{
"Parameters": {
"BUCKET_RAW_NAME": "rawbucket",
"LOCALSTACK_ENDPOINT": "http://127.17.0.1:4566/"
}
}
```
(I also tried 127.0.0.1, localhost, localstack, ...)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.