If you keep getting BadRequest trying to connect to localstack S3 container, this might help

This is a quick gotcha if you keep getting BadRequest without a useful error message trying to connect another container to localstack S3.

Here’s part of the error I was getting:

  message: null,
code: 'BadRequest',
region: null,
time: 2020-12-02T13:41:48.630Z,
requestId: null,
extendedRequestId: undefined,
cfId: undefined,
statusCode: 400,
retryable: false,
retryDelay: 85.98033816170914

If you’re getting this error, check if you’ve specified a DEFAULT_REGION in the docker-compose.yml file.

Here’s what my docker-compose.yml looked like:

# docker-compose.ymllocalstack:    
image: localstack/localstack:latest
- SERVICES=s3:4566

# I won't include the whole localstack config as it isn't relevant.

If you’ve specified a default region, when you initialise the AWS SDK, it will expect a region to be passed in.

For eg:

// correct ✅const AWS = require('aws-sdk')const s3 = new AWS.S3({
endpoint: '',
accessJeyId: 'someAccessKeyId',
secretAccessKey: 'someSecretAccessKey',
s3ForcePathStyle: true,
region: 'us-east-1', // read note below*
*NOTE: If you've got a DEFAULT_REGION in you docker-compose.yml file, you will need to pass in a region

I thought I’d write this up in case it helps someone else. The error message wasn’t very helpful and I spent more time than I’d like to admit on it.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store