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 10 in AWS by akhtar
• 33,720 points
120 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 10 by MD
• 79,930 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 2 days ago in AWS by MD
• 79,930 points
6 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 2 days ago in AWS by MD
• 79,930 points
7 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,650 points
403 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 in AWS by MD
• 79,930 points
60 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 10 in AWS by MD
• 79,930 points
71 views