在 Python 中使用 ARN iam 将文件上传到 Amazon s3 存储桶
Uploading files to Amazon s3 bucket using ARN iam in Python
我得到了一个存储桶名称,其 ARN 编号如下:
arn:aws:iam::<>:user/user-name
我还获得了访问密钥。
我知道这可以使用 boto 来完成。
Connect to s3 bucket using IAM ARN in boto3
如上link需要用'sts'吗?
如果是这样,为什么我会获得访问密钥?
首先,我建议您安装 AWS Command-Line Interface (CLI),它提供了一个用于访问 AWS 的命令行。
然后您可以通过 运行:
将您的凭据存储在配置文件中
aws configure
它会提示您输入访问密钥和密钥,它们将存储在配置文件中。
然后,您需要参考 S3 — Boto 3 documentation 以了解如何从 Python 访问 Amazon S3。
下面是一些示例代码:
import boto3
client = boto3.client('s3', region_name = 'ap-southeast-2') # Change as appropriate
client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')
我得到了一个存储桶名称,其 ARN 编号如下:
arn:aws:iam::<>:user/user-name
我还获得了访问密钥。
我知道这可以使用 boto 来完成。
Connect to s3 bucket using IAM ARN in boto3
如上link需要用'sts'吗? 如果是这样,为什么我会获得访问密钥?
首先,我建议您安装 AWS Command-Line Interface (CLI),它提供了一个用于访问 AWS 的命令行。
然后您可以通过 运行:
将您的凭据存储在配置文件中aws configure
它会提示您输入访问密钥和密钥,它们将存储在配置文件中。
然后,您需要参考 S3 — Boto 3 documentation 以了解如何从 Python 访问 Amazon S3。
下面是一些示例代码:
import boto3
client = boto3.client('s3', region_name = 'ap-southeast-2') # Change as appropriate
client.upload_file('/tmp/hello.txt', 'mybucket', 'hello.txt')