[英]specify role while uploading file to s3
我的 aws 配置文件中有一個配置文件clientProject
設置。 我的 aws 憑據文件中也有必要的憑據。 但是,如果我從頭開始創建一個 Python 腳本:
import boto3
s3 = boto3.resource('s3')
s3.meta.client.upload_file('catalog.json', 'testunzipping','catalog.json')
我無法運行它,因為在上傳文件之前,我需要在 AWS 上切換/擔任角色,以便我可以獲得必要的權限。
boto3.exceptions.S3UploadFailedError: Failed to upload catalog.json to testunzipping/catalog.json: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
如何使用獨立腳本指定配置文件和現有角色?
根據此處的 boto3 文檔,您雲使用以下內容來使用您的clientProject
配置文件。
session = boto3.Session(profile_name='clientProject')
s3 = session.resource('s3')
s3.meta.client.upload_file('catalog.json', 'testunzipping','catalog.json')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.