【发布时间】: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 代码。
【问题讨论】:
-
这是实际的业务需求还是您正在为某些课程做的作业?
-
是的,这是针对业务需求的演示。在以下代码上需要帮助 - 目标组引用创建的 Web 服务器 - 应用程序负载均衡器 - 监听器引用负载均衡器和目标组 无法用于上述 YAML 代码模板的地方请告知
-
为什么无法使用上述文档?
-
感谢分享链接。 docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… 链接混乱。
标签: yaml amazon-cloudformation ubuntu-18.04