简体   繁体   中英

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM