Elastic Beanstalk:如何使用 .ebextensions 从另一个 Cloudformation 堆栈导入 VPCId?

问题描述

是否可以使用 AWS Elastic Beanstalk 中 Fn:ImportValue 中的 option_settings 从其他 Cloudformation 堆栈中导入 VPCId 的值?

或者此时必须对值进行硬编码?任何指针将不胜感激!

这是一个有效的 .ebextensions/config,它部署成功: 有关更多上下文,该应用程序是一个简单的 node.js express 服务器,我正在使用 eb cli

部署堆栈
#.ebextensions/vpc.config
option_settings:
  aws:ec2:vpc:
    ELBScheme: internal
    VPCId: vpc-0620a64be983c807a
    subnets: "subnet-0b2e7f79bdd53a4da,subnet-0f0f6471dc6130f0a,subnet-0ce654446fd42509a"
    ELBsubnets: "subnet-0b2e7f79bdd53a4da,subnet-0ce654446fd42509a"
    AssociatePublicIpAddress: true

这是将 VPCId 导出到另一个 cloudformation 堆栈中且值为 vpc-0620a64be983c807a 的损坏示例:

option_settings:
  aws:ec2:vpc:
    ELBScheme: internal
    VPCId: { "Fn::ImportValue" : "VPCId" }
    subnets: "subnet-0b2e7f79bdd53a4da,subnet-0ce654446fd42509a"
    AssociatePublicIpAddress: true

这是错误代码,在弹性 beanstalk 包上传到 AWS 后,它似乎没有插入 vpcID

2021-01-19 10:36:59    ERROR   "option_settings" in one of the configuration files Failed validation. More details to follow.
2021-01-19 10:36:59    ERROR   Invalid option value: '["subnet-0ce654446fd425098","subnet-0b2e7f79bdd53a4df","subnet-0f0f6471dc6130f0c"]' (Namespace: 'aws:ec2:vpc',OptionName: 'subnets'): Specify the VPC ID and make sure all subnets exist.
2021-01-19 10:37:00    ERROR   Invalid option value: 'subnet-0b2e7f79bdd53a4df,subnet-0f0f6471dc6130f0c,subnet-0ce654446fd425098' (Namespace: 'aws:ec2:vpc',OptionName: 'ELBsubnets'): Specify the VPC ID and make sure all subnets exist.
2021-01-19 10:37:00    ERROR   Failed to launch environment.

更新: 建议使用反引号和引号,但它似乎在 VPC 查找中按字面意思处理整个字符串

2021-01-19 11:31:05    ERROR   The VPC '`{ "fn::importvalue" :"vpcid" }`' does not exist.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)