簡體   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