I'm using CloudFormation to define a subnet and EC2 instance. I want to allocate a particular private IP address to an EC2 instance and have attempted to do so using the resource definitions such as those below.
When I try to deploy my template the creation of the NetworkInterface resource fails with the message 'Address is in subnet's reserved address range'. I've tried to work this out but am not making progress. How do I define my subnet with a range of private IP addresses which I can apply to my EC2 instances?
Thanks.
Note: The whole template contains other resources and so I've attempted to reduce it to the important components, hence the below is purposely incomplete.
"SharedVPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.10.0.0/16",
"EnableDnsHostnames": true,
"EnableDnsSupport": true,
"InstanceTenancy": "default"
}
},
"SharedVPCPrivateSubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": "eu-west-1a",
"CidrBlock": "10.10.129.0/24",
"MapPublicIpOnLaunch": false,
"VpcId": {
"Ref": "SharedVPC"
}
}
},
"DbServerEC2Instance": {
"Type": "AWS::EC2::Instance",
"Properties": {
"KeyName": "WindowsEC2",
"InstanceType": "t2.micro",
"AvailabilityZone": "eu-west-1a",
"ImageId": {
"Ref": "DbServerEC2ImageAMI"
},
"IamInstanceProfile": {
"Ref": "EC2InstanceProfile"
},
"NetworkInterfaces": [{
"NetworkInterfaceId": {
"Ref": "DbServerEC2InstanceNetworkInterface"
},
"DeviceIndex" : "0"
}]
}
},
"DbServerEC2InstanceNetworkInterface": {
"Type": "AWS::EC2::NetworkInterface",
"Properties": {
"Description": "eth0",
"PrivateIpAddresses": [{
"PrivateIpAddress": "10.10.129.2",
"Primary": "true"
},
{
"PrivateIpAddress": "10.10.129.3",
"Primary": "false"
}
],
"SourceDestCheck": "true",
"SubnetId": {
"Ref": "SharedVPCPrivateSubnet1"
}
}
}