amazon-web-services - CloudFormation 可以部署到默认子网吗?
问题描述
我正在使用 CloudFormation 尝试将 EC2 和 RDS 部署到安全组中,EC2 SG 作为 WebDMZ 组,RDS SG 仅对来自 EC2 组的流量开放。
安全组工作正常,但 EC2 和 RDS 实例都给我同样的错误,他们无法在 VPC XYZ123 中找到安全组,其中 XYZ123 是默认 VPC 的 ID——唯一的 VPC,我已验证我的安全组确实在该 VPC 中。
我在另一个模板中尝试了我的 EC2 的代码并且它有效,但前提是我专门将它分配给公共子网。
此代码是学术性的,不适用于生产。我不能让我的资产部署到默认子网或随机子网吗?实例级别的安全组不是吗,所以只要它是正确的 VPC 就应该没问题?我错过了什么?
Resources:
04WebDMZ:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Open to HTTP, HTTPS and SSH on all ports
GroupName: 04WebDMZ
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: 04WebDMZ
04DatabaseSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Open to 04WebDMZ
GroupName: 04DatabaseSG
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
SourceSecurityGroupName:
Ref: 04WebDMZ
Tags:
- Key: Name
Value: 04DatabaseSG
04PublicEC2:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-047a51fa27710816e
InstanceType: t2.micro
KeyName: my_key_pair
NetworkInterfaces:
- AssociatePublicIpAddress: True
DeviceIndex: 0
DeleteOnTermination: True
Tags:
- Key: Name
Value: 04PublicEC2
UserData:
!Base64 |
#!/bin/bash
yum install httpd php php-mysql -y
cd /var/www/html
wget https://wordpress.org/wordpress-5.1.1.tar.gz
tar -xzf wordpress-5.1.1.tar.gz
cp -r wordpress/* /var/www/html/
rm -rf wordpress
rm -rf wordpress-5.1.1.tar.gz
chmod -R 755 wp-content
chown -R apache:apache wp-content
service httpd start
chkconfig httpd on
04RDS:
Type: AWS::RDS::DBInstance
Properties:
DBSecurityGroups:
- Ref: 04DatabaseSG
AllocatedStorage: '5'
DBInstanceClass: db.t2.small
Engine: MySQL
MasterUsername: admin
MasterUserPassword: admin
Tags:
- Key: Name
Value: 04RDS
DeletionPolicy: Snapshot
解决方案
推荐阅读
- jquery - 如何解决赛普拉斯和 jQuery 的类型标识符冲突?
- xamarin - Xamarin 窗体:如何在 Xamarin.iOS 中使用 UIViewPropertyAnimator
- rust - 为 f64 设置查找表的最佳方法
- outlook - Outlook 插件 在桌面上固定插件
- ruby-on-rails - 在 Rail 5.4.2 中找不到 rails_admin.css
- php - 域重定向到 URI mod rewrite 或 301 重定向?
- azure - 键入“az login”时,Azure Cli 给了我权限错误
- python - 如何重定向python导入?
- nestjs - NestJS 无法解析 gRPC 微服务客户端
- sql - 当 2 和 2 加入时很难进行 3 加入工作就好了