[英]how to pass reference to existing VPC to a cloudformation template?
I am creating a cloudformation template, with few resources, couple of lambda functions, S3 bucket.see code below, it is work on progress and so far I have a S3 bucket and a lamda function triggered by S3.我正在创建一个 cloudformation 模板,资源很少,有几个 lambda 函数,S3 存储桶。请参阅下面的代码,它正在进行中,到目前为止,我有一个 S3 存储桶和一个由 S3 触发的 lamda function。 we have vpc defined in our team that we are supposed to use.我们在我们的团队中定义了我们应该使用的 vpc。 I would like to add private subnet under that vpc for my lambda function and assign public subnet for the s3 bucket.我想在该 vpc 下为我的 lambda function 添加私有子网,并为 s3 存储桶分配公有子网。 how to get reference of the vpc, and pass it to my template and use it?如何获取 vpc 的引用,并将其传递给我的模板并使用它? sample code will be helpful.示例代码会有所帮助。
AWSTemplateFormatVersion: 2010-09-09
Resources:
# S3 Bucket
S3Bucket:
Type: AWS::S3::Bucket
# Functions
S3-Lambda-trigger:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: lambda.handler
Description: s3 object creation triggers lambda
Runtime: nodejs12.x
Events:
S3Bucket:
Type: S3
Properties:
Bucket: !Ref S3Bucket
Events: 's3:ObjectCreated:*'
# Permissions
Allow-lamda-invocation-s3:
Type: AWS::Lambda::Permission
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref S3-Lambda-trigger
Principal: s3.amazonaws.com
SourceArn: !GetAtt S3Bucket.Arn
how to get reference of the vpc, and pass it to my template and use it?如何获取 vpc 的引用,并将其传递给我的模板并使用它?
One way would be through AWS-Specific Parameter Types , specifically AWS::EC2::VPC::Id
, in a Parameters
section.一种方法是通过AWS-Specific Parameter Types ,特别是AWS::EC2::VPC::Id
,在Parameters
部分。
For example:例如:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
VPCId:
Type: AWS::EC2::VPC::Id
Resources:
MySubnet:
Type: AWS::EC2::Subnet
Properties:
# other properties
VpcId: !Ref VPCId
Thanks to this, when creating the stack in AWS Console, you would be able to choose existing VPCId to pass to the template.多亏了这一点,在 AWS 控制台中创建堆栈时,您可以选择现有的 VPCId传递给模板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.