【问题标题】:Create CloudFormation template in YAML to create following resources and output在 YAML 中创建 CloudFormation 模板以创建以下资源和输出
【发布时间】:2019-11-05 19:10:43
【问题描述】:

在 AZ 中创建 Web 服务器实例,创建目标组,使用 CloudFormation 模板创建负载均衡器来管理 AWS 资源。

这里的场景如下:

创建 CloudFormation 模板以创建以下资源和输出

  • 必填参数 ○ Web 服务器安全组
  • Web 服务器:AMI - Ubuntu Server 18.04 LTS,t2.micro,使用用户数据安装 apache Web 服务器
  • 引用已创建 Web 服务器的目标组
  • 应用负载均衡器
  • 监听器引用负载均衡器和目标组
  • 输出负载均衡器 URL

使用 YAML:

AWSTemplateFormatVersion: 2010-09-09
Description: AWS cloudformation template to create ec2 instance with http apache web server, target group, and load balancer.
This template creates one or more Amazon EC2 instances and an application Load Balancer.
Parameters:
  KeyName:
    Description: Name of an existing EC2 Keypair to enable SSH access to the instance
    Type: AWS::EC2::KeyPair::KeyName
    Default: project04
    ConstraintDescription: must be the name of an existing EC2 KeyPair.
  InstanceType:
    Description: WebServer EC2 instance type
    Type: String
    Default: t2.micro
  AmiId:
    Description: Ubuntu 18.04 LTS AMI Id
    Type: String
    Default: ami-0ac019f4fcb7cb7e6
  SSHLocation:
    Description: The IP address range that can be used to SSH to instances
    Type: String
    MinLength: 9
    MaxLength: 18
    Default: 0.0.0.0/0
    AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
    ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.

Resources:
 WebServerInstance:
   Type: AWS::EC2::Instance
   Properties:
     InstanceType: !Ref 'InstanceType'
     SecurityGroups: [!Ref 'WebServerSecurityGroup']
     KeyName: !Ref 'KeyName'
     ImageId: !Ref "AmiId"
     UserData:
         Fn::Base64:
             Fn::Join: 
               -"
               --|
                     #!/bin/bash
                    -'# Launching Instance'
                    -|
                     sudo apt-get update -y
                     sudo apt-get install -y apache2
  WebServerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
    GroupDescription: Enable SSH traffic and HTTP access
       SecurityGroupIngress:
         IpProtocol: tcp
         FromPort: 22
         ToPort: 22
         CidrIp: !Ref 'SSHLocation'
         IpProtocol: tcp
         FromPort: 80
         ToPort: 80
         CidrIp: 0.0.0.0/0
Outputs:
  URL:
    Description: The URL of the sample website
    Value: !Join ['', ['http://', !GetAtt [WebServerInstance, PublicDNSName]]] 

需要帮助并提供 YAML 代码:

  • 引用已创建 Web 服务器的目标组
  • 应用负载均衡器
  • 监听器引用负载均衡器和目标组

请建议为上面无法找到的 CloudFormation 模板提供 YAML 代码。

【问题讨论】:

标签: yaml amazon-cloudformation ubuntu-18.04


【解决方案1】:

您可以尝试cloudkast 为 aws cloudformation 资源生成 yaml 或 json sn-p。 cloudkast 是一个在线的 cloudformation 模板生成器。它非常直观且易于使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-19
    • 2017-07-15
    • 2019-07-05
    • 1970-01-01
    • 2017-06-12
    • 2023-02-09
    • 2017-03-01
    • 2019-06-13
    相关资源
    最近更新 更多