gpt4 book ai didi

amazon-web-services - 指定 VPC SubnetID/SecurityGroupIds 数组到 aws cli cloudformation 部署

转载 作者:行者123 更新时间:2023-12-03 07:39:19 25 4
gpt4 key购买 nike

我正在使用 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:预期类型:JSONArray,找到:String #/VpcConfig/SubnetIds:预期类型:JSONArray,找到: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

希望这对其他人有帮助。

关于amazon-web-services - 指定 VPC SubnetID/SecurityGroupIds 数组到 aws cli cloudformation 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73818468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com