在python代码中,python,amazon-cloudformation,troposphere"/>

首页 > 解决方案 > 如何修复预期在python代码中

问题描述

我正在使用 Troposphere 创建 CloudFormation 模板。

如果我使用变量或字符串,我会收到错误 -<class 'troposphere.efs.FileSystem'>, expected <type 'basestring'>

我是对流层和 python 的新手,因此感谢您的帮助。

我使用字符串时的代码

MyEFSMountTarget1a = t.add_resource(MountTarget(
    "MyEFSMountTarget1a",
    FileSystemId=(efs_file_system),
    SecurityGroups=["sg-0c69656095ee1a5b8"],
    SubnetId="subnet-091b67136896b2be8"
))

使用变量时的代码

MyEFSMountTarget1a = t.add_resource(MountTarget(
    "MyEFSMountTarget1a",
    FileSystemId=(efs_file_system),
    SecurityGroups=[efs_security_group],
    SubnetId=PublicSubnet1a
))

错误: <class 'troposphere.efs.MountTarget'>: MyEFSMountTarget1a.FileSystemId is <class 'troposphere.efs.FileSystem'>, expected <type 'basestring'>

我正在做的是从另一个 cloudformation 堆栈导入值并在另一个堆栈中使用它们。

这是我填充变量的方式 -

efs_security_group = ImportValue(Join("-", [params.ENVIRONMENT, "efsSecurityGroup"]),)
PublicSubnet1a = ImportValue(Join("-", [params.ENVIRONMENT, "PublicSubnet1a"]),)

它们被正确填充,我认为它们是突出的字符串 - 它们是。所以我想我不能对 SecurityGroups 或 SubnetId 使用字符串?我需要将字符串转换为基本字符串吗?如何?

厄尼

标签: pythonamazon-cloudformationtroposphere

解决方案


我的错误 - 这是文件系统 id - 我忘了给它添加一个引用 FileSystemId=Ref(efs_file_system),


推荐阅读