I upload to and download from S3 with a presigned post/url. The presigned url/post are generated with boto3 in the Lambda function (it is deployed with zappa).
While I add my AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID as env variable works perfectly. Then I removed my credentials and I add an IAM role to lambda to full access to S3 bucket. After that the lambda return with the presigned URL and getObject is working well, however when i want to upload object through the URL, it returns an InvalidAccessKeyId error. The used key id ASIA... which means those are temporary credentials.
It seems that the lambda does not use IAM role, or what is the problem?
class S3Api:
def __init__(self):
self.s3 = boto3.client(
's3',
region_name='eu-central-1'
)
def generate_store_url(self, key):
return self.s3.generate_presigned_post(FILE_BUCKET,
key,
Fields=None,
Conditions=None,
ExpiresIn=604800)
def generate_get_url(self, key):
return self.s3.generate_presigned_url('get_object',
Params={'Bucket': FILE_BUCKET,
'Key': key},
ExpiresIn=604800)
My result for sts:getCallerIdentity:
{
'UserId': '...:dermus-api-dev',
'Account': '....',
'Arn': 'arn:aws:sts::....:assumed-role/dermus-api-dev-ZappaLambdaExecutionRole/dermus-api-dev',
'ResponseMetadata': {
'RequestId': 'a1bd7c31-0199-472e-bff7-b93a4f855450',
'HTTPStatusCode': 200,
'HTTPHeaders': {
'x-amzn-requestid': 'a1bd7c31-0199-472e-bff7-b93a4f855450',
'content-type': 'text/xml',
'content-length': '474',
'date': 'Tue, 09 Mar 2021 08:36:30 GMT'
},
'RetryAttempts': 0
}
}
dermus-api-dev-ZappaLambdaExecutionRole role is attached to dermus-api-dev lambda.