PROBLEM
YAML formating error, not able to determine what is missing to correct in this YAML format online tool: https://www.anyjson.in/yaml-formatter to check my YAML script.
YAML Effort to fix format
I have tried Value: Public Subnet 2; Value: PublicSubnet2; Value: 'PublicSubnet2'. All with the same format error in YAML formatter online
YAML Error
the following error on syntax for YAML was given on the YAML script below. I have changed it several times and not able to resolve the format yaml error.
I have tried Value: Public Subnet 2; Value: PublicSubnet2; Value: 'PublicSubnet2'. Now at a loss on what next to correct the YAML format for line: 82/83, as per the error below (next)
Line 83: while parsing a block collection in "<unicode string>", line 82, column 9: - Key: Name ^ (line: 82) expected <block end>, but found '?' in "<unicode string>", line 83, column 9: Value: 'PublicSubnet2' ^ (line: 83)
YAML Script
On the LINE 82/83
- Key: Name
Value: 'PublicSubnet2'
The full scope of Key/Value YAML script is found in this block:
Subnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: Ref VPC
CidrBlock: 10.0.30.0/24
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: 'PublicSubnet2'
YAML LINK
The full YAML format attempt is on this link:
YAML Formatter - Format and Beautify YAML Documents Online
Line 83: while parsing a block collection
in "<unicode string>", line 82, column 9:
- Key: Name
^ (line: 82)
expected <block end>, but found '?'
in "<unicode string>", line 83, column 9:
Value: 'PublicSubnet2'
^ (line: 83)
Enter YAML input below:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
...
245.
246.
247.
248.
249.
250.
251.
line numbers map to below YAML script:
Parameters:
DBName:
Default: mydb
Description: My database
Type: String
MinLength: '1'
MaxLength: '64'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
DBUsername:
Type: String
Description: Master username for the RDS instance
Default: admin
DBPassword:
Type: String
NoEcho: true
Description: Master password for the RDS instance
Default: password
DBInstanceClass:
Default: db.m5.large
Description: DB instance class
Type: String
DBAllocStore:
Default: '50'
Description: The size of the database (GiB)
Type: Number
MinValue: '20'
MaxValue: '65536'
DBInstance:
Default: DBInstance
Description: My database instance
Type: String
MinLength: '1'
MaxLength: '63'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: VPC
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: 'aws--s3--bucket'
IGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: VPC Internet Gateway
Subnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.20.0/24
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: 'PrivateSubnet1'
Subnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: Ref VPC
CidrBlock: 10.0.30.0/24
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: 'PublicSubnet2'
resource aws_lb_test:
name: test-lb-tf
internal: false
load_balancer_type: application
security_groups:
- aws_security_group.lb_sg.id
subnets:
- for subnet in aws_subnet.public: subnet.id
enable_deletion_protection: true
access_logs:
bucket: aws_s3_bucket.lb_logs.id
prefix: aws_lb_test
enabled: true
tags:
Environment: production
SSHSecGrp:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: Ref VPC
GroupDescription: Security group egress
SecurityGroupEgress:
- CidrIp: 127.0.0.111/32
IpProtocol: "-1"
EC2SecGrp:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: Ref VPC
GroupDescription: EC2 Security Group
GroupName: aws-security-grp
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
SourceSecurityGroupId:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 127.0.0.112/32
EC2Net1:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
SecurityGroupIds:
- Ref EC2SecGrp
SubnetId: !Ref Subnet1
KeyName: EC2Net1
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
#echo "<h1>Hello from Region us-east-2b</h1>" > /var/www/html/index.html
EC2Net2:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
SecurityGroupIds:
- !Ref EC2SecGrp
SubnetId: Ref Subnet2
KeyName: EC2Net1\2
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
#echo "<h1>Hello from Region us-east-2b</h1>" > /var/www/html/index.html
S3BuckPol:
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: Ref S3Bucket
SecurityGroupIds:
- Ref EC2SecGrp
KeyName: S3BucketPol
PolicyDocument:
Statement:
- Effect: Allow
Action: 's3:*'
Resource: !Sub 'arn:aws:s3:::${S3Bucket}/*'
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:user/@matthew'
EC2TgtGrp:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 15
HealthyThresholdCount: 5
Matcher:
HttpCode: '200'
Name: EC2TargetGroup
Port: 80
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '20'
Targets:
- Id: Ref EC2Net2
Port: 80
UnhealthyThresholdCount: 3
EC2TgtGrp:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 15
HealthyThresholdCount: 5
Matcher:
HttpCode: '200'
Name: EC2TargetGroup
Port: 80
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '20'
Targets:
- Id: Ref EC2Net1
Port: 80
UnhealthyThresholdCount: 3
LoadBalance:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: aws-elb-load-balance
Scheme: internet-facing
Subnets:
- Ref Subnet1
AppLBListner:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: Ref VPC
LoadBalancerArn: Ref LoadBalance
Port: 80
Protocol: HTTP
MyRDS:
Type: 'AWS::RDS::DBInstance'
Properties:
DBInstanceIdentifier: Ref DBInstance
DBName: Ref DBName
DBInstanceClass: Ref DBInstanceClass
AllocatedStorage: Ref DBAllocStore
Engine: MySQL
MasterUsername: Ref DBUsername
MasterUserPassword: Ref DBPassword
SecurityGroupIds:
- Ref EC2SecGrp
KeyName: MyRDS
You have wrong indentation for Value
as well misspelled Ref
. It should be:
Subnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.30.0/24
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: 'PublicSubnet2'
You have to check remaining parts of the template for similar issues.