cloudyr / aws.s3

Amazon Simple Storage Service (S3) API Client
https://cloud.r-project.org/package=aws.s3
381 stars 147 forks source link

Problem with S3 and Lambda #390

Open mfcava opened 3 years ago

mfcava commented 3 years ago

Hi, I'm trying to access an AWS S3 bucket within a lambda function with a custom docker image. I've setup a script to get a list of files with this code:

Sys.setenv("AWS_ACCESS_KEY_ID" = aws_s3_key, "AWS_SECRET_ACCESS_KEY" = aws_s3_secret, "AWS_DEFAULT_REGION" = "eu-west-2")

aws_s3_bucket_name <- "my-bucket"

f <- aws.s3::get_bucket(bucket = aws_s3_bucket_name, url_style = "path")

I've got no problem in running my script within docker but, as soon as I try the same function in lambda I got this error:

2021-06-15T00:24:17.833+02:00 $ Code : chr "InvalidToken" 2021-06-15T00:24:17.846+02:00 $ Message : chr "The provided token is malformed or otherwise invalid." 2021-06-15T00:24:17.847+02:00 $ Token-0 : chr "IQoJb3JpZ/BoNzJXuwChJ2R5p"| truncated 2021-06-15T00:24:17.847+02:00 $ RequestId: chr "CP2CBX9PA95G3X2X" 2021-06-15T00:24:17.848+02:00 $ HostId : chr "pTlkIhvhCTLPTiXwSBHL/qq7Y=" 2021-06-15T00:24:17.848+02:00 - attr(*, "headers")=List of 8 2021-06-15T00:24:17.849+02:00 ..$ x-amz-bucket-region: chr "eu-west-2" 2021-06-15T00:24:17.849+02:00 ..$ x-amz-request-id : chr "CP2CBX9PA95G3X2X" 2021-06-15T00:24:17.866+02:00 ..$ x-amz-id-2 : chr "pTlkIhvhCTLPTiXwW4vMexnz/qq7Y=" 2021-06-15T00:24:17.867+02:00 ..$ content-type : chr "application/xml" 2021-06-15T00:24:17.867+02:00 ..$ transfer-encoding : chr "chunked" 2021-06-15T00:24:17.867+02:00 ..$ date : chr "Mon, 14 Jun 2021 22:24:17 GMT" 2021-06-15T00:24:17.868+02:00 ..$ server : chr "AmazonS3" 2021-06-15T00:24:17.868+02:00 ..$ connection : chr "close" ... ...

Maybe it's just my fault as I'm quite new to was-lambda but I still not get why the script works in my local docker.

TrainedLoop commented 1 month ago

I have the same problem here, did you find any solution?

TrainedLoop commented 1 month ago

I removed the session token and it works

Sys.setenv(AWS_ACCESS_KEY_ID = Sys.getenv("s3_key")) Sys.setenv(AWS_SECRET_ACCESS_KEY = Sys.getenv("s3_secret")) Sys.setenv(AWS_DEFAULT_REGION = Sys.getenv("s3_region")) Sys.unsetenv("AWS_SESSION_TOKEN")