CloudFormationでエラーがでる。
Q&A
Closed
解決したいこと
ec2とrdsをCloudFormationで作成したいのですが、なぜかエラーがでる。
発生している問題・エラー
2024-11-17 00:47:12 UTC+0900
rds
ROLLBACK_IN_PROGRESS
-
The following resource(s) failed to create: [MyEC2Instance, MyRDSInstance]. Rollback requested by user.
2024-11-17 00:47:11 UTC+0900
MyEC2Instance
CREATE_FAILED
-
Resource creation cancelled
2024-11-17 00:47:09 UTC+0900
MyRDSInstance
CREATE_FAILED
-
Resource handler returned message: "The parameter AllocatedStorage must be provided and must not be null. (Service: Rds, Status Code: 400, Request ID: 7810ee92-f317-4981-be17-66bce0403783)" (RequestToken: 1abc3e94-92b0-ba49-419b-e77ee8bfcd1b, HandlerErrorCode: InvalidRequest)
または、問題・エラーが起きている画像をここにドラッグアンドドロップ
該当するソースコード
AWSTemplateFormatVersion: '2010-09-09'
Description: Create an EC2 instance and RDS database
Parameters:
InstanceType:
Type: String
Description: EC2 instance type
Default: t2.micro
DBInstanceClass:
Type: String
Description: RDS database instance class
Default: db.t3.micro
KeyName:
Type: String
Description: EC2 Key Pair name for SSH access
Default: my-key-pair # Replace with your actual key pair name
Resources:
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-08ce76bae392de7dc # Update based on your region
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
SecurityGroupIds:
- !Ref MySecurityGroup
MySecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow SSH and DB access
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0 # Restrict to specific IP range for security
- IpProtocol: tcp
FromPort: 3306
ToPort: 3306
CidrIp: 0.0.0.0/0 # Restrict to specific IP range for security
VpcId: vpc-026a7387dd6843290 # Replace with your actual VPC ID
MyRDSInstance:
Type: AWS::RDS::DBInstance
Properties:
DBInstanceClass: !Ref DBInstanceClass
Engine: mysql
MasterUsername: myuser
MasterUserPassword: b2h2an0cbn # Use AWS Secrets Manager or Parameters for sensitive values
DBName: mydatabase
VPCSecurityGroups:
- !GetAtt MySecurityGroup.GroupId
DBSubnetGroupName: !Ref MyDBSubnetGroup
MyDBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Subnet group for RDS
SubnetIds:
- subnet-0c0b17fe43556d272 # Replace with actual Subnet IDs
- subnet-0e490e7b684f3b4aa # Replace with actual Subnet IDs
自分で試したこと
chatgptで修正してもらった。
よろしくお願いします。