如何在lambda云形成模板中添加vpcconfig部分

发布于 2025-02-10 02:01:44 字数 1057 浏览 0 评论 0原文

为了能够与Internet连接,我想使用CloudFormation模板在我的lambda中添加VPCCONFIG。 AWS提供了一个示例,说明了如何将lambda与VPC 在这里。但是我的要求有点扩展。我已经从其他模板中导出了导出部分中的子网ID和安全组ID,从那里我必须在lambda模板中导入相同的内容。首先,我在lambda模板的参数部分中添加了其密钥,然后遵循上述URL中提到的过程。

我的代码就像: 在lambda模板的参数部分中:

Parameters:
 SecurityGroupId:
   Description: |-
     VPC security group id
   Type:String
   Default: 'sg-importkey'
SubnetId1:
   Description: |-
     Subnet id 1
   Type:String
   Default: 'sb1-importkey'
SubnetId2:
   Description: |-
     Subnet id 2
   Type:String
   Default: 'sb2-importkey'

然后在lambda函数的属性部分中,添加了vpCsection:

VpcConfig:
  SecurityGroupIds: !ImportValue
    'fn::sub': 'SecurityGroupId'
  SubnetIds: !importValue
    'fn::sub': 'SubnetId1'
    'fn::sub': 'SubnetId2'

部署时获取错误: “属性验证因资源函数而失败,并使用消息:#/vpcconfig/securitygroupsids:预期类型:jsonarray,找到:字符串:

To be able to connect with internet, I want to add vpcconfig section in my lambda using cloudformation template. AWS has given one example of how to connect lambda with VPC here . But my requirement is little bit extended. I have exported subnet ids and security group id in export section from other template and from there i have to import the same in my lambda template. to do that first i am adding its key in parameter section of lambda template and then follow the process mentioned in mentioned url above.

My code is like :
in parameter section of lambda template :

Parameters:
 SecurityGroupId:
   Description: |-
     VPC security group id
   Type:String
   Default: 'sg-importkey'
SubnetId1:
   Description: |-
     Subnet id 1
   Type:String
   Default: 'sb1-importkey'
SubnetId2:
   Description: |-
     Subnet id 2
   Type:String
   Default: 'sb2-importkey'

Then in properties section of lambda function, added following vpcsection:

VpcConfig:
  SecurityGroupIds: !ImportValue
    'fn::sub': 'SecurityGroupId'
  SubnetIds: !importValue
    'fn::sub': 'SubnetId1'
    'fn::sub': 'SubnetId2'

getting error while deploying:
"Properties validation failed for resource function with message:#/VpcConfig/SecurityGroupsIds: expected type: JSONArray, found:String"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2025-02-17 02:01:44

SecurityGroupsIds必须是 list ,而不是字符串:

VpcConfig:
  SecurityGroupIds: 
     - Fn::ImportValue:
         !Sub "${SecurityGroupId}"
  SubnetIds: 
     - Fn::ImportValue:
         !Sub "${SubnetId1}"
     - Fn::ImportValue:
         !Sub "${SubnetId2}"

对于subnetids相同。

SecurityGroupsIds must be a list, not a string:

VpcConfig:
  SecurityGroupIds: 
     - Fn::ImportValue:
         !Sub "${SecurityGroupId}"
  SubnetIds: 
     - Fn::ImportValue:
         !Sub "${SubnetId1}"
     - Fn::ImportValue:
         !Sub "${SubnetId2}"

Same for SubnetIds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文