【问题标题】:Specify Array of VPC SubnetID / SecurityGroupIds to aws cli cloudformation deploy将 VPC SubnetID / SecurityGroupIds 数组指定到 aws cli cloudformation deploy
【发布时间】:2022-09-23 21:43:35
【问题描述】:

我正在使用 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\' 指定参数,但找不到将数组传递给 cloudformation 的单一格式。

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

有什么提示吗?

    标签: amazon-web-services amazon-cloudformation aws-cli


    【解决方案1】:

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

    
    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

    希望这对其他人有帮助。

    【讨论】:

      猜你喜欢
      • 2019-09-16
      • 2015-06-24
      • 2017-03-12
      • 2015-08-01
      • 1970-01-01
      • 2021-01-14
      • 2021-06-28
      • 2018-02-07
      • 1970-01-01
      相关资源
      最近更新 更多