- edited description
Creating s3 bucket using aws cli from container on same docker network fails
I am using the cgswong/aws docker image (which just provides a container with the AWS Cli) to interact with localstack.
These are the operations I performed to setup a docker network with the localstack container running in detached mode and open a bash session in cgswong/aws
user@host $ docker network create <network_name>
user@host $ docker network connect --alias localstack <network_name> <localstack_container_name>
user@host $ docker run --rm --network <network_name> -e AWS_ACCESS_KEY_ID=no-key-needed -e AWS_SECRET_ACCESS_KEY=no-key-needed -e AWS_DEFAULT_REGION=us-east-1 -it cgswong/aws bash
I listed my buckets and got an expected result
user@cgswong/aws $ aws --endpoint-url="http://localstack:4572" s3api list-buckets
{
"Owner": {
"DisplayName": "webfile",
"ID": "bcaf1ffd86f41161ca5fb16fd081034f"
},
"Buckets": []
}
However, when I try to execute create-bucket
user@cgswong/aws $ aws --endpoint-url="http://localstack:4572" s3api create-bucket --bucket my-bucket
An error occurred (NoSuchBucket) when calling the CreateBucket operation: The specified bucket does not exist
I performed the same operation using the AWS Cli installed on my host machine and got
user@host $ aws --endpoint-url="http://localhost:<port_to_4572>" s3api create-bucket --bucket my-bucket
user@host $ aws --endpoint-url="http://localhost:<port_to_4572>" s3api list-buckets
{
"Owner": {
"DisplayName": "webfile",
"ID": "bcaf1ffd86f41161ca5fb16fd081034f"
},
"Buckets": [
{
"CreationDate": "2006-02-03T16:45:09.000Z",
"Name": "my-bucket"
}
]
}
Output of aws --version
ran on the docker container
aws-cli/1.11.41 Python/2.7.12 Linux/4.9.13-moby botocore/1.5.4
Output of aws --version
ran on the host machine
aws-cli/1.11.66 Python/2.7.10 Darwin/16.5.0 botocore/1.5.29
Comments (11)
-
reporter -
Account Deactivated Can you run the
list-buckets
command from within your AWS CLI container, or does that command also fail?Can you access the port at all? What if you run
telnet localstack 4572
from your AWS CLI container - does it connect successfully?For easier debugging, it might be useful to use the
--debug
CLI flag when callingcreate-bucket
. Can you post the debug output here? (at least the relevant portions of it) -
reporter The following is run in an environment that is setup following the steps I listed in the first codeblock above including this command to start the localstack container.
$ docker run -d atlassianlabs/localstack
Can you run the list-buckets command from within your AWS CLI container, or does that command also fail?
$ aws --endpoint-url="http://localstack:4572" s3api list-buckets { "Owner": { "DisplayName": "webfile", "ID": "bcaf1ffd86f41161ca5fb16fd081034f" }, "Buckets": [] }
Can you access the port at all? What if you run
telnet localstack 4572
from your AWS CLI container - does it connect successfully?Telnet connects to the port and hangs for user input
$ telnet localstack 4572 ^C
Giving HTTP-like payload, getting the followed response
$ telnet localstack 4572 GET /foo.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>500 Internal Server Error</title> <h1>Internal Server Error</h1> <p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p> Connection closed by foreign host
For easier debugging, it might be useful to use the
--debug
CLI flag when callingcreate-bucket
. Can you post the debug output here? (at least the relevant portions of it)I'm not sure what portions are considered relevant. Here is the result of running
create-bucket ... --debug
$ aws --endpoint-url="http://localstack:4572" s3api create-bucket --bucket my-bucket --debug 2017-04-07 06:14:11,227 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/1.11.41 Python/2.7.12 Linux/4.9.13-moby botocore/1.5.4 2017-04-07 06:14:11,227 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['--endpoint-url=http://localstack:4572', 's3api', 'create-bucket', '--bucket', 'my-bucket', '--debug'] 2017-04-07 06:14:11,227 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_scalar_parsers at 0x7f1ccb4699b0> 2017-04-07 06:14:11,227 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider_cache at 0x7f1ccb958aa0> 2017-04-07 06:14:11,229 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/lib/python2.7/site-packages/botocore/data/s3/2006-03-01/service-2.json 2017-04-07 06:14:11,252 - MainThread - botocore.hooks - DEBUG - Event service-data-loaded.s3: calling handler <function register_retries_for_service at 0x7f1ccc254320> 2017-04-07 06:14:11,252 - MainThread - botocore.handlers - DEBUG - Registering retry handlers for service: s3 2017-04-07 06:14:11,255 - MainThread - botocore.hooks - DEBUG - Event building-command-table.s3api: calling handler <function add_waiters at 0x7f1ccb472b90> 2017-04-07 06:14:11,258 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/lib/python2.7/site-packages/botocore/data/s3/2006-03-01/waiters-2.json 2017-04-07 06:14:11,259 - MainThread - awscli.clidriver - DEBUG - OrderedDict([(u'acl', <awscli.arguments.CLIArgument object at 0x7f1ccade6c50>), (u'bucket', <awscli.arguments.CLIArgument object at 0x7f1ccade6c90>), (u'create-bucket-configuration', <awscli.arguments.CLIArgument object at 0x7f1ccade6cd0>), (u'grant-full-control', <awscli.arguments.CLIArgument object at 0x7f1ccade6d10>), (u'grant-read', <awscli.arguments.CLIArgument object at 0x7f1ccade6d50>), (u'grant-read-acp', <awscli.arguments.CLIArgument object at 0x7f1ccade6d90>), (u'grant-write', <awscli.arguments.CLIArgument object at 0x7f1ccade6e10>), (u'grant-write-acp', <awscli.arguments.CLIArgument object at 0x7f1ccade6e50>)]) 2017-04-07 06:14:11,259 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.s3api.create-bucket: calling handler <function add_streaming_output_arg at 0x7f1ccb469ed8> 2017-04-07 06:14:11,259 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.s3api.create-bucket: calling handler <function add_cli_input_json at 0x7f1ccb95f8c0> 2017-04-07 06:14:11,260 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.s3api.create-bucket: calling handler <function unify_paging_params at 0x7f1ccb4f4ed8> 2017-04-07 06:14:11,262 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/lib/python2.7/site-packages/botocore/data/s3/2006-03-01/paginators-1.json 2017-04-07 06:14:11,267 - MainThread - botocore.hooks - DEBUG - Event building-argument-table.s3api.create-bucket: calling handler <function add_generate_skeleton at 0x7f1ccb4ed320> 2017-04-07 06:14:11,267 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.s3api.create-bucket: calling handler <bound method CliInputJSONArgument.override_required_args of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7f1ccade6910>> 2017-04-07 06:14:11,268 - MainThread - botocore.hooks - DEBUG - Event before-building-argument-table-parser.s3api.create-bucket: calling handler <bound method GenerateCliSkeletonArgument.override_required_args of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7f1ccade6ed0>> 2017-04-07 06:14:11,269 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.acl: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,269 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.bucket: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,269 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.s3.create-bucket: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f1ccb937650> 2017-04-07 06:14:11,270 - MainThread - awscli.arguments - DEBUG - Unpacked value of u'my-bucket' for parameter "bucket": u'my-bucket' 2017-04-07 06:14:11,270 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.create-bucket-configuration: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,270 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.grant-full-control: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,270 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.grant-read: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,270 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.grant-read-acp: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,270 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.grant-write: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,271 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.grant-write-acp: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,271 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.cli-input-json: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,271 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.s3.create-bucket.generate-cli-skeleton: calling handler <function uri_param at 0x7f1ccb97c6e0> 2017-04-07 06:14:11,271 - MainThread - botocore.hooks - DEBUG - Event calling-command.s3api.create-bucket: calling handler <bound method GenerateCliSkeletonArgument.generate_json_skeleton of <awscli.customizations.generatecliskeleton.GenerateCliSkeletonArgument object at 0x7f1ccade6ed0>> 2017-04-07 06:14:11,272 - MainThread - botocore.hooks - DEBUG - Event calling-command.s3api.create-bucket: calling handler <bound method CliInputJSONArgument.add_to_call_parameters of <awscli.customizations.cliinputjson.CliInputJSONArgument object at 0x7f1ccade6910>> 2017-04-07 06:14:11,272 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env 2017-04-07 06:14:11,272 - MainThread - botocore.credentials - INFO - Found credentials in environment variables. 2017-04-07 06:14:11,273 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/lib/python2.7/site-packages/botocore/data/endpoints.json 2017-04-07 06:14:11,286 - MainThread - botocore.client - DEBUG - Registering retry handlers for service: s3 2017-04-07 06:14:11,289 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x7f1ccc222c08> 2017-04-07 06:14:11,289 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.s3: calling handler <function add_generate_presigned_url at 0x7f1ccc222398> 2017-04-07 06:14:11,289 - MainThread - botocore.args - DEBUG - The s3 config key is not a dictionary type, ignoring its value of: None 2017-04-07 06:14:11,293 - MainThread - botocore.endpoint - DEBUG - Setting s3 timeout as (60, 60) 2017-04-07 06:14:11,293 - MainThread - botocore.client - DEBUG - Using S3 path style addressing. 2017-04-07 06:14:11,294 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.s3.CreateBucket: calling handler <function validate_bucket_name at 0x7f1ccc2540c8> 2017-04-07 06:14:11,294 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.s3.CreateBucket: calling handler <bound method S3RegionRedirector.redirect_from_cache of <botocore.utils.S3RegionRedirector object at 0x7f1ccad30dd0>> 2017-04-07 06:14:11,294 - MainThread - botocore.hooks - DEBUG - Event before-parameter-build.s3.CreateBucket: calling handler <function generate_idempotent_uuid at 0x7f1ccc252cf8> 2017-04-07 06:14:11,295 - MainThread - botocore.hooks - DEBUG - Event before-call.s3.CreateBucket: calling handler <function add_expect_header at 0x7f1ccc254500> 2017-04-07 06:14:11,295 - MainThread - botocore.hooks - DEBUG - Event before-call.s3.CreateBucket: calling handler <bound method S3RegionRedirector.set_request_url of <botocore.utils.S3RegionRedirector object at 0x7f1ccad30dd0>> 2017-04-07 06:14:11,295 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=CreateBucket) (verify_ssl=True) with params: {'body': '', 'url': u'http://localstack:4572/my-bucket', 'headers': {'User-Agent': 'aws-cli/1.11.41 Python/2.7.12 Linux/4.9.13-moby botocore/1.5.4'}, 'context': {'client_region': 'us-east-1', 'signing': {'bucket': u'my-bucket'}, 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7f1ccad308d0>}, 'query_string': {}, 'url_path': u'/my-bucket', 'method': u'PUT'} 2017-04-07 06:14:11,295 - MainThread - botocore.hooks - DEBUG - Event request-created.s3.CreateBucket: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f1ccad30850>> 2017-04-07 06:14:11,295 - MainThread - botocore.auth - DEBUG - Calculating signature using hmacv1 auth. 2017-04-07 06:14:11,295 - MainThread - botocore.auth - DEBUG - HTTP request method: PUT 2017-04-07 06:14:11,295 - MainThread - botocore.auth - DEBUG - StringToSign: PUT Fri, 07 Apr 2017 06:14:11 GMT /my-bucket 2017-04-07 06:14:11,297 - MainThread - botocore.endpoint - DEBUG - Sending http request: <PreparedRequest [PUT]> 2017-04-07 06:14:11,298 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): localstack 2017-04-07 06:14:11,302 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "PUT /my-bucket HTTP/1.1" 404 241 2017-04-07 06:14:11,303 - MainThread - botocore.parsers - DEBUG - Response headers: {'date': 'Fri, 07 Apr 2017 06:14:11 GMT', 'content-length': '241', 'content-type': 'text/html; charset=utf-8', 'server': 'Werkzeug/0.12.1 Python/2.7.13'} 2017-04-07 06:14:11,303 - MainThread - botocore.parsers - DEBUG - Response body: <?xml version="1.0" encoding="UTF-8"?> <Error> <Code>NoSuchBucket</Code> <Message>The specified bucket does not exist</Message> <BucketName>None</BucketName> <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID> </Error> 2017-04-07 06:14:11,303 - MainThread - botocore.hooks - DEBUG - Event needs-retry.s3.CreateBucket: calling handler <botocore.retryhandler.RetryHandler object at 0x7f1ccae51f50> 2017-04-07 06:14:11,304 - MainThread - botocore.retryhandler - DEBUG - No retry needed. 2017-04-07 06:14:11,304 - MainThread - botocore.hooks - DEBUG - Event needs-retry.s3.CreateBucket: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7f1ccad30dd0>> 2017-04-07 06:14:11,304 - MainThread - botocore.hooks - DEBUG - Event after-call.s3.CreateBucket: calling handler <function enhance_error_msg at 0x7f1ccb4696e0> 2017-04-07 06:14:11,306 - MainThread - awscli.clidriver - DEBUG - Exception caught in main() Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 197, in main return command_table[parsed_args.command](remaining, parsed_args) File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 333, in __call__ return command_table[parsed_args.operation](remaining, parsed_globals) File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 503, in __call__ call_parameters, parsed_globals) File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 622, in invoke client, operation_name, parameters, parsed_globals) File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 634, in _make_client_call **parameters) File "/usr/lib/python2.7/site-packages/botocore/client.py", line 253, in _api_call return self._make_api_call(operation_name, kwargs) File "/usr/lib/python2.7/site-packages/botocore/client.py", line 543, in _make_api_call raise error_class(parsed_response, operation_name) NoSuchBucket: An error occurred (NoSuchBucket) when calling the CreateBucket operation: The specified bucket does not exist 2017-04-07 06:14:11,311 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255 An error occurred (NoSuchBucket) when calling the CreateBucket operation: The specified bucket does not exist
-
Account Deactivated This is a tricky one. The underlying S3 mock implementation basically only considers
localhost
as a special domain name, and it gets confused once we call the API via thelocalstack
domain name (it believes that this domain name refers to the bucket name, which is basically also how the real S3 API works).I've pushed a change to allow
localstack
(or any other local domain name which does not contain a ".") as the host for the S3 API, should be fixed in version0.3.5
. The Docker image has not been pushed yet, I will push the new version tomorrow. -
reporter Is that going to solve this error though (snippet from my
--debug
dump):<?xml version="1.0" encoding="UTF-8"?> <Error> <Code>NoSuchBucket</Code> <Message>The specified bucket does not exist</Message> <BucketName>None</BucketName> <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID> </Error>
I tried running the same test for
create-bucket
andlist-objects
after creating a bucket namedlocalstack
from the host machine to test the hostname theory.It looks like it's not recognizing any bucket name
<BucketName>None</BucketName>
. I just got the same result when runninglist-objects
. -
reporter I did verify that running
put-object
andlist-objects
worked from the host machine against thelocalstack
bucket (without restarting the environment from the comment immediately leading this one). That does make the hostname idea to be a likely issue. -
reporter Out of curiosity, I changed the
/etc/hosts
file of theaws
container and changed localhost to point to thelocalstack
container's IP address. I was successfully able to performput-object
,list-objects
, andget-object
against thelocalstack
bucket using the endpoint urlhttp://localhost:4572
-
Account Deactivated Good catch. Yes, mocking the S3 API unfortunately is a bit annoying, when it comes to those hostname related issues. As I said, the fix in version
0.3.5
should work, will build and push the image asap. -
Account Deactivated Docker image version 0.3.5 pushed. Closing this for now, please re-open if the problem persists.
-
Account Deactivated - changed status to resolved
-
reporter I verified that my use case has been resolved. Thanks for the work @w_hummer
- Log in to comment
Added
user@host
anduser@cgswong/aws
for context in command line