localstack / awscli-local

💲 "awslocal" - Thin wrapper around the "aws" command line interface for use with LocalStack
Apache License 2.0
1.09k stars 86 forks source link

awslocal vs aws #60

Closed mmg10 closed 2 years ago

mmg10 commented 2 years ago

The awscli-local is not compatible with the aws cli from AWS. If I create a kinesis stream with

aws --endpoint-url=http://localhost:4566 kinesis create-stream \
    --stream-name ride_predictions \
    --shard-count 1

I can't view the streams using

awslocal kinesis list-streams

I can only view the streams using

aws --endpoint-url=http://localhost:4566 kinesis list-streams

And vice-versa.

Since in both cases it is using localstack, they should give the same result (which is not the case!)

alexrashed commented 2 years ago

Hi @mmg10. In addition to changing the endpoint, awslocal also modifies the following environment variables:

In your case, I guess you are not defining the region as an env var, but as a config in ~/.aws/config. Which in turn leads to using two different regions. Defining the region in the awslocal call would most likely fix your issue. Could you maybe verify that this fixes your issue?

Just if you're interested, this happens here: https://github.com/localstack/awscli-local/blob/cca765afc7d0e63455d6ca36f277e36c2c15412a/bin/awslocal#L98-L123

mmg10 commented 2 years ago

Hi @alexrashed

Thanks, your tip helped me. Both of the following two methods work

awslocal kinesis list-streams --region us-east-2

OR

export AWS_DEFAULT_REGION=us-east-2
awslocal kinesis list-streams

So is there any advantage of using awslocal at all? Seems like I would be better off creating an alias to aws --endpoint-url=http://localhost:4566.

alexrashed commented 2 years ago

As mentioned in the README, it is a viable alternative to just use an alias instead of using awslocal. As mentioned in the particular section this works for most use cases. The issue you ran into is actually a feature. awslocal sets a unified set of default configurations (credentials, region) if it is not explicitly set. This simplifies the scripts built with awslocal and simplifies sharing those scripts (since the resulting resources will be the same for different users).