python - AWS Lambda unable to GET a file from S3 -
hi have lambda (python3.6) below unable read file s3, though lambda in role has unfettered permissions s3 (iam policy below).
the lambda attempts retrieve file s3 , write temporary location. blocks on calling s3.bucket()
, times out (even timeout in minutes).
what's weird it's timing out without exception, , not rejecting call s3.bucket()
kind of permission error.
this pretty basic, i'm @ loss sorted out.
import boto3 botocore import exceptions def lambda_handler(event, context): key = event['image'] bucket = event['bucket'] tempfile = '/tmp/%s-%s' % (bucket, key) print('(p) bucket: %s::%s' % (bucket, key)) print('(p) tempfile: %s' % tempfile) s3 = boto3.resource('s3') print('(p) resource intiialized') try: b = s3.bucket(bucket) print('(p) bucket info: %s [%s]' % (b.name, b.creation_date)) b.download_file(prefixed_key, tempfile) print('(p} file downloaded %s' % tempfile) except exceptions.paramvalidationerror e: return {"statuscode": 400, "body": 'paramvalidationerror: [%s]' % e} except exceptions.clienterror e: message = '[%s]: [%s]' % (e.response['error']['code'], e.response['error']['message']) return {"statuscode": e.response['responsemetadata']['httpstatuscode'], "body": message} print('(p) image downloaded s3 , stored at: %s' % tempfile) return none
iam policy role has is:
{ "version": "2012-10-17", "statement": [ { "effect": "allow", "action": "s3:*", "resource": [ "arn:aws:s3:::my_bucket", "arn:aws:s3:::my_bucket/*" ] } ] }
example logs:
22:42:43 start requestid: 61c60167-839d-11e7-97b1-a772bbde2609 version: $latest start requestid: 61c60167-839d-11e7-97b1-a772bbde2609 version: $latest 22:42:43 (p) bucket: my_bucket::my_key 22:42:43 (p) tempfile: /tmp/my_bucket/my_key 22:42:43 (p) resource intiialized 22:43:13 end requestid: 61c60167-839d-11e7-97b1-a772bbde2609 end requestid: 61c60167-839d-11e7-97b1-a772bbde2609
the issue narrowed down misconfiguration of vpc. configured run outside of vpc don't need now, , worked.
Comments
Post a Comment