Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awslocal vs aws #60

Closed
mmg10 opened this issue Jul 15, 2022 · 3 comments
Closed

awslocal vs aws #60

mmg10 opened this issue Jul 15, 2022 · 3 comments

Comments

@mmg10
Copy link

mmg10 commented Jul 15, 2022

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
Copy link
Member

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

  • AWS_DEFAULT_REGION - is set to the value of DEFAULT_REGION, or the value of AWS_DEFAULT_REGION, or us-east-1.
  • AWS_ACCESS_KEY_ID - is set to test if it's not set
  • AWS_SECRET_ACCESS_KEY - is set to test if it's not set
  • AWS_DATA_PATH - is unset if it's set

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:

awscli-local/bin/awslocal

Lines 98 to 123 in cca765a

def prepare_environment():
# prepare env vars
env_dict = os.environ.copy()
env_dict['PYTHONWARNINGS'] = os.environ.get(
'PYTHONWARNINGS', 'ignore:Unverified HTTPS request')
if os.environ.get('DEFAULT_REGION'):
if os.environ.get('AWS_DEFAULT_REGION'):
msg = 'Environment variable "AWS_DEFAULT_REGION" will be overwritten by "DEFAULT_REGION"'
print('INFO: %s' % msg)
env_dict['AWS_DEFAULT_REGION'] = os.environ.get(
'DEFAULT_REGION')
else:
env_dict['AWS_DEFAULT_REGION'] = os.environ.get(
'AWS_DEFAULT_REGION', 'us-east-1')
env_dict['AWS_ACCESS_KEY_ID'] = os.environ.get(
'AWS_ACCESS_KEY_ID', 'test')
env_dict['AWS_SECRET_ACCESS_KEY'] = os.environ.get(
'AWS_SECRET_ACCESS_KEY', 'test')
env_dict.pop('AWS_DATA_PATH', None)
# update environment variables in the current process
os.environ.update(env_dict)
return env_dict

@mmg10
Copy link
Author

mmg10 commented Jul 18, 2022

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.

@mmg10 mmg10 closed this as completed Jul 18, 2022
@alexrashed
Copy link
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants