在 CFN 资源提供程序测试中创建 S3 存储桶时出现 IllegalLocationConstraintException
IllegalLocationConstraintException whilst creating an S3 bucket in CFN resource provider test
我正在使用 cloudformation cli 创建一个 Cloudformation 资源提供程序。当我尝试使用 cfn test
在本地测试我的资源时,出现以下错误:
An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The us-east-2 location constraint is incompatible for the region specific endpoint this request was sent to.
我的代码如下所示:
s3 = session.client("s3")
s3.create_bucket(Bucket='mybucket123',CreateBucketConfiguration={'LocationConstraint': 'us-east-2'})
我也尝试过其他地区,并且在没有 LocationConstraint 的情况下尝试过,但我在地区代码为 undefined
的单词中遇到了同样的错误:
s3 = session.client("s3")
s3.create_bucket(Bucket='mybucket123')
cfn test
实际上使用 sam local start-lambda
在 sam local 中运行代码所以我有点困惑为什么我什至需要这里的区域?
有什么想法吗?
您的 client
也必须设置为您想要的区域:
s3 = session.client("s3", region_name='us-east-2')
s3.create_bucket(Bucket='mybucket123',CreateBucketConfiguration={'LocationConstraint': 'us-east-2'})
您可以简单地添加和覆盖位置限制。
将 s3 存储桶文件复制到本地示例
通过使用 AWS CLI:(需要配置)
aws s3 sync --region --source-region s3:/// ~/
我正在使用 cloudformation cli 创建一个 Cloudformation 资源提供程序。当我尝试使用 cfn test
在本地测试我的资源时,出现以下错误:
An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The us-east-2 location constraint is incompatible for the region specific endpoint this request was sent to.
我的代码如下所示:
s3 = session.client("s3")
s3.create_bucket(Bucket='mybucket123',CreateBucketConfiguration={'LocationConstraint': 'us-east-2'})
我也尝试过其他地区,并且在没有 LocationConstraint 的情况下尝试过,但我在地区代码为 undefined
的单词中遇到了同样的错误:
s3 = session.client("s3")
s3.create_bucket(Bucket='mybucket123')
cfn test
实际上使用 sam local start-lambda
在 sam local 中运行代码所以我有点困惑为什么我什至需要这里的区域?
有什么想法吗?
您的 client
也必须设置为您想要的区域:
s3 = session.client("s3", region_name='us-east-2')
s3.create_bucket(Bucket='mybucket123',CreateBucketConfiguration={'LocationConstraint': 'us-east-2'})
您可以简单地添加和覆盖位置限制。 将 s3 存储桶文件复制到本地示例
通过使用 AWS CLI:(需要配置)
aws s3 sync --region --source-region s3:/// ~/