Let's have a look at creating the public subnet. The following code block shows the mechanism:
letsPollPublicSubnet: Type: AWS::EC2::Subnet Properties: VpcId: Ref: letsPollVPC AvailabilityZone: ${self:provider.region}a CidrBlock: 10.0.0.0/24 MapPublicIpOnLaunch: true Tags: - Key: Name Value: Lets Poll VPC Public Subnet 1
A few things to note about the code:
- We specify the VPC for this subnet by using the Ref function as before.
- We allocate a CidrBlock for it.
- We specify the availability zones for this subnet.
- We set MapPublicIpOnLaunch to be true. This will ensure that any resource launched in this subnet will have a public IP and hence internet access.
- We specify the tags for easy handling.