【发布时间】:2021-09-08 22:45:12
【问题描述】:
我正在尝试在对流层的add_resource 中添加一个if 语句,但我不能。有什么解决办法吗?
s3_bucket = t.add_resource(Bucket(
"MyBucket",
if 2>1:
BucketName="bucket1",
else:
BucketName="bucket2",
CorsConfiguration=CorsConfiguration(
"CorsConfiguration",
CorsRules=[CorsRules(
"AllowOrganization",
AllowedMethods=["GET"],
AllowedOrigins=["*"],
)]
),
Tags=Tags(
Environment="aa",
)
))
编辑:
我也尝试过使用三元运算符,但是没有用。
BucketName= if 2 > 1: "bucket2" else: "bucket3",
【问题讨论】:
-
@mkrieger1 不幸的是没有。我基本上是在 add_resource 函数参数中尝试这样做。我得到这个“如果”没有定义PylancereportUndefinedVariable github.com/cloudtools/troposphere/blob/master/troposphere/…
-
那是因为你没有正确使用它。
BucketName="bucket1" if 2>1 else "bucket2"是正确的语法。
标签: python amazon-cloudformation troposphere