gpt4 book ai didi

python-2.7 - 如何使用 AWS Lambda python 创建 S3 存储桶?

转载 作者:行者123 更新时间:2023-12-05 04:09:56 25 4
gpt4 key购买 nike

我正在使用 Python 创建一个 AWS Lambda 函数。我想创建 S3 存储桶,但出现错误,因为我提供的存储桶名称不是 JSON 可序列化的。

这是我使用 Lambda 创建存储桶的代码:

import boto from boto 
import s3 from boto.s3.connection
import S3Connection

def lambda_handler(event, context):
conn = S3Connection('access_key','secret_access_key')
print "Connection:",conn
bucket = conn.create_bucket('bucketname')
print bucket
return bucket

最佳答案

来自 Creating and Using Amazon S3 Buckets boto3 文档:

import boto3

s3 = boto3.client('s3')
s3.create_bucket(Bucket='my-bucket')

桶名规则:

  • 存储桶名称的长度可以3 到 63 个字符,并且只能包含小写字符、数字、句点和破折号。
  • 存储桶名称中的每个标签都必须以小写字母或数字开头。
  • 存储桶名称不能包含下划线、以破折号结尾、有连续的句点或在句号旁边使用破折号。
  • 存储桶名称的格式不能为 IP 地址 (198.51.100.24)。

关于python-2.7 - 如何使用 AWS Lambda python 创建 S3 存储桶?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45207654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com