Aws credentials

Hello,

I’m trying to use a ServerModule to upload a file to s3.
while the aws key & secret are configured as “app secrets”, i’m getting “Access Denied” error

Please note the using the exact same key+secret locally works.
I’ve printed the key+secret to the console to make sure boto3 can use them and they printed ok.

This is the part from the ServerModule:

AWS_ACCESS_KEY_ID = anvil.secrets.get_secret(‘aws_key’)
AWS_SECRET_ACCESS_KEY = anvil.secrets.get_secret(‘aws_secret’)
AWS_DEFAULT_REGION = “us-east-1”

This is the Error:

ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
at /usr/local/lib/python3.6/site-packages/botocore/client.py, line 612
  called from /usr/local/lib/python3.6/site-packages/botocore/client.py, line 314
  called from /usr/local/lib/python3.6/site-packages/boto3/resources/action.py, line 83
  called from /usr/local/lib/python3.6/site-packages/boto3/resources/factory.py, line 520
  called from ServerModule1, line 53
  called from Form6, line 20

ok, just needed to pass them to the boto3.client explicitly
It works

1 Like

Nice to see you figured it out :+1:

For future reference, you can mark the accepted answer by clicking on the ellipsis below the comment:

forum_more

and then on the tick icon:

forum_accepted

A more detailed example NOT using app secrets if your just experimenting. Suggest not putting keys in sources this way.

s3 = boto3.resource(service_name=‘s3’,region_name=“us-east-1”,aws_access_key_id=‘access-id-here’,aws_secret_access_key=‘secret-key-here’)

for bucket in s3.buckets.all():
print(bucket.name)

1 Like