Monra01
Monra01

Reputation: 11

Cross-account-access Lambda S3 with access key

I am fairly new to AWS and try to put a object on S3 with a Lambda function, which is in another account than the bucket. From the account of the S3 bucket I just got the access key & secret access key of a role, which can put things in the bucket. I just own the account with the Lambda function. By searching for an answer I just found out that I need to modify the bucket policy of the other account, which is not really a solution. Is there a solution where I can directly use the access key and secret key inside the lambda function? Thank you really much for your help in advance.

Upvotes: 1

Views: 883

Answers (1)

Marcin
Marcin

Reputation: 238249

Is there a solution where I can directly use the access key and secret key inside the lambda function?

This is a very bad practice and shouldn't be used. The proper way is through cross-account roles and specifically for lambda.

Nevertheless, if for some reason you must use access key and secret key inside the lambda function, then each AWS SDK client will allow you to specify them. For example, in boto3 for python, you can use Session or client to provide the credentials. For client:

import boto3

s3 = boto3.client('s3', aws_secret_access_key=<ddd>, aws_session_token=<ddfdfd>

Upvotes: 1

Related Questions