How to create a security group in AWS with Boto3

0 votes

Hi Team,

I want to create a security group in AWS so that I can launch an EC2 instance. But I don't know how to create a security group with the Boto3 module. Can anyone help me with this?

Oct 11, 2020 in AWS by akhtar
• 38,230 points
3,783 views

1 answer to this question.

0 votes

Hi@akhtar,

You can create a new security group using the create_security_group() method, and assign it to our VPC. Then you can define inbound rules to only allow SSH port number 22 as shown below.

# Create a security group and allow SSH inbound rule through the VPC
securitygroup = ec2.create_security_group(GroupName='SSH-ONLY', Description='only allow SSH traffic', VpcId=vpc.id)
securitygroup.authorize_ingress(CidrIp='0.0.0.0/0', IpProtocol='tcp', FromPort=22, ToPort=22)
answered Oct 11, 2020 by MD
• 95,440 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

How to create an Auto Scaling group using a launch configuration in AWS?

Hi@akhtar, You can create an Auto Scaling group with ...READ MORE

answered Nov 26, 2020 in AWS by MD
• 95,440 points
656 views
0 votes
1 answer

How to create a Cluster Security Group in RedShift?

Hi@akhtar, You can create a new Amazon Redshift security ...READ MORE

answered Nov 27, 2020 in AWS by MD
• 95,440 points
775 views
0 votes
1 answer
0 votes
1 answer

How can I return XML from boto calls?

I don't think there's an officially supported ...READ MORE

answered Jul 20, 2018 in AWS by Cloud gunner
• 4,670 points
1,244 views
0 votes
1 answer

How to create a VPC in AWS using Boto3?

Hi@akhtar, Amazon Web Services enables you to create ...READ MORE

answered Oct 9, 2020 in AWS by MD
• 95,440 points
1,415 views
0 votes
1 answer

How to create an AWS EC2 Instance in the VPC with Boto3 module?

Hi@akhtar, You can use a network interface in ...READ MORE

answered Oct 11, 2020 in AWS by MD
• 95,440 points
2,131 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP