【问题标题】:How to fix expected <type 'basestring'> in python code如何在 python 代码中修复预期的 <type 'basestring'>
【发布时间】:2019-09-06 19:22:15
【问题描述】:

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

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

我是对流层和 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
))

错误:&lt;class 'troposphere.efs.MountTarget'&gt;: MyEFSMountTarget1a.FileSystemId is &lt;class 'troposphere.efs.FileSystem'&gt;, expected &lt;type 'basestring'&gt;

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

这是我填充变量的方式 -

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

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

厄尼

【问题讨论】:

  • 我不熟悉troposphere,但是试试from troposphere import Base64,然后转换:SubnetId=Base64(PublicSubnet1a)?

标签: python amazon-cloudformation troposphere


【解决方案1】:

我的错误 - 它是文件系统 ID - 我忘记向它添加引用 FileSystemId=Ref(efs_file_system),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 2023-02-21
    • 1970-01-01
    • 2019-03-25
    • 1970-01-01
    相关资源
    最近更新 更多