繁体   English   中英

将 VPC SubnetID / SecurityGroupIds 数组指定到 aws cli cloudformation deploy

[英]Specify Array of VPC SubnetID / SecurityGroupIds to aws cli cloudformation deploy

我正在使用 aws-cli 在多个环境中部署我的堆栈,并且需要对堆栈可用的子网/安全组进行参数化。

我的 SAM 模板中有一个部分定义子网和安全组,如下所示:

  EnvSubnets:
    Description: Define subnet ids
    Type: 'List<AWS::EC2::Subnet::Id>'
  EnvSecGroups:
    Description: Security Groups
    Type: 'List<AWS::EC2::SecurityGroup::Id>'

我使用 `aws cloudformation deploy... --parameter-overrides file://env.json' 指定 arguments 但找不到将 arrays 传递给 cloudformation 的单一格式。

我不断收到以下错误: #/VpcConfig/SecurityGroupIds: expected type: JSONArray, found: String #/VpcConfig/SubnetIds: expected type: JSONArray, found: String

有什么提示吗?

似乎目前不支持这 - 我最终使用了由用户可覆盖参数驱动的嵌套模板:


AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: 'SAM Template for XXXXX XXXXX'

Parameters:
  LambdaRole:
    Description: Define exiting Lambda role to provide permissions
    Type: String
  LambdaImage:
    Description: Define Lambda image URI
    Type: String
  LambdaVPCInclude:
    Description: S3 URI of the YAML for the S3 VPC section
    Type: String

Resources:
  FOO:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: !Ref LambdaImage
      Architectures:
        - x86_64
      MemorySize: 1024
      Timeout: 900  
      Role: !Ref LambdaRole
      'Fn::Transform':
        Name: 'AWS::Include'
        Parameters:
          Location: !Ref LambdaVPCInclude
    Metadata:
      SamResourceId: FOO
Outputs:
  QuantUniverse:
    Description: FOO Lambda Function ARN
    Value: !GetAtt FOO.Arn

在 S3 存储桶中,我有一个包含 VPC 配置的文件:

VpcConfig:
  SubnetIds:
    - subnet-*****************
    - subnet-*****************
    - subnet-*****************
  SecurityGroupIds:
    - sg-*****************
    - sg-*****************

并将此文件的 S3 URI 作为LambdaVPCInclude的覆盖传递给aws cloudformation deploy

希望这对其他人有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM