amazon-web-services - 在无服务器 yaml 配置中使用 fn::split 不起作用
问题描述
我正在使用无服务器框架在 AWS 上部署 API。我的serverless.yml
文件中有以下内容:
custom:
vpcSettings:
private:
securityGroupIds:
private:
fn::split:
delimiter: ','
value: ${env:VPC_SG_ID}
VPC_SG_ID
包含以下字符串:sg-1111111111,sg-222222222,sg-3333333333
但是,在部署应用程序时,我收到以下错误:
An error occurred: MyLambdaFunction - Value of property SecurityGroupIds must be of type List of String.
如果我对 SGs 列表进行硬编码,它可以正常工作:
custom:
vpcSettings:
private:
securityGroupIds:
private:
- "sg-1111111111"
- "sg-2222222222"
- "sg-3333333333"
为什么 fn::split 函数不返回字符串列表?
编辑:
以下配置导致相同的错误
custom:
vpcSettings:
private:
securityGroupIds:
private:
Fn::Split:
- ','
- ${env:VPC_SG_ID}
解决方案
如果将安全组作为输入参数添加到模板
Parameters:
VPCSGID:
Type: String
Description: Comma separated Security Groups
安全组可以拆分!Split
为
SecurityGroupIds: !Split [",", !Ref VPCSGID]
可以拆分Fn:Split
为
SecurityGroupIds: { "Fn::Split": [",", !Ref VPCSGID] }
sam deploy 的参数可以传递为
sam deploy --parameter-overrides 'ParameterKey=VPCSGID,ParameterValue=sg-011111,sg-222222'
推荐阅读
- python - 正则表达式匹配负后瞻、递归模式和负前瞻
- python - 选项 -s 已弃用,请使用 -video_size。未找到选项 video_size
- c# - Arduino 不向 WinForms 应用程序发送数据
- c# - 删除 DataTables SearchBuilder 中的条件
- javascript - Node.js:“无法读取未定义的属性‘toString’
- c# - 基于变量的自动映射器中的映射
- matlab - 如何从Matlab中的for循环将向量的一部分插入矩阵?
- python - 保存之前的 n 个训练权重
- reactjs - 如何在 React 应用程序中使用样式化组件
- javascript - “TypeError:events.map 不是函数”我在创建新事件时遇到此错误