简体   繁体   English

如何将对现有 VPC 的引用传递给 cloudformation 模板?

[英]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.

相关问题 如何在 AWS CloudFormation 模板中为新的 SecurityGroup 使用现有 VPC - How to use existing VPC in AWS CloudFormation template for new SecurityGroup 如何在 CloudFormation yaml 模板中引用现有资源? - How to reference existing resources in CloudFormation yaml template? 如何在 Cloudformation 模板中引用现有的 ELB DNSName - how to reference existing ELB DNSName in Cloudformation template 如何在 CloudFormation 中引用默认 VPC? - How can I reference the Default VPC in CloudFormation? 如何通过 CloudFormation 模板将 lambda 放入 VPC - how to put the lambda in VPC by CloudFormation template 如何在我的新 CloudFormation 模板中引用现有角色? - How can I reference an existing role in my new CloudFormation template? 如何在CloudFormation模板中引用现有的AWS Cert? - How do I reference an existing AWS Cert in a CloudFormation template? 在创建子网时引用CloudFormation脚本中的现有AWS VPC Id - Reference an existing AWS VPC Id in CloudFormation script when creating subnets 从VPC内的另一个云形成模板引用SecurityGroup - Reference SecurityGroup from another cloudformation template inside VPC 如何在新的 Cloudformation 模板中引用 Cloudformation 资源? - How to reference Cloudformation Ressources in a new Cloudformation template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM