How to create subnets in a vpc and in subnet 1 create Ec2 and in subnet 2 create Rds using boto3

0 votes
How to create subnets in a vpc and in subnet 1 create Ec2 and in subnet 2 create Rds using boto3
Aug 28 in AWS by pranaya
211 views

1 answer to this question.

0 votes

To create the subnet in VPC:

subnet = c.create_subnet(vpc.id, '10.0.0.0/25')
subnet.id
u'subnet-xxxxxx'
subnet.state
u'pending'
subnet.cidr_block
u'10.0.0.0/25'
subnet.available_ip_address_count
123
subnet.availability_zone
u'us-east-1b'

Create an ec2 instance on that subnet:

instances = ec2.create_instances(
    ImageId='ami-835b4efa', InstanceType='t2.micro', MaxCount=1, MinCount=1,
    NetworkInterfaces=[{'SubnetId': subnet.id, 'DeviceIndex': 0, 'AssociatePublicIpAddress': True, 'Groups': [sec_group.group_id]}])
instances[0].wait_until_running()
print(instances[0].id)

Have a look at this for creating rds using boto

https://gist.github.com/ikai/c79be091f98da1b709ee

answered Aug 28 by Yesha

Related Questions In AWS

0 votes
1 answer

How to create subnets in a vpc using boto3?

Here is the simple way of implementing ...READ MORE

answered Dec 4, 2018 in AWS by Shuvodip Ghosh
666 views
0 votes
1 answer
0 votes
1 answer

Unable to delete subnets in a VPC using boto3.

.terminate is used for instances and not ...READ MORE

answered Dec 4, 2018 in AWS by Shuvodip Ghosh
144 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to create an EC2 instance using Python?

Hey JunDevOps, Have a look these scripts: 1. ...READ MORE

answered Jun 24 in AWS by Aysha

edited Jun 25 859 views