首页 > 解决方案 > 在 CFN 资源提供程序测试中创建 S3 存储桶时出现 IllegalLocationConstraintException

问题描述

我正在使用 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 using 中运行代码,sam local start-lambda所以我有点困惑为什么我什至需要一个区域?

有任何想法吗?

标签: amazon-web-servicesamazon-s3amazon-cloudformationaws-cloudformation-custom-resource

解决方案


client还必须设置为您想要的区域:

s3 = session.client("s3", region_name='us-east-2')
s3.create_bucket(Bucket='mybucket123',CreateBucketConfiguration={'LocationConstraint': 'us-east-2'})

推荐阅读