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, 2020 in AWS by akhtar
• 38,170 points
544 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, 2020 by MD
• 95,160 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,160 points
79 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 26, 2020 in AWS by MD
• 95,160 points
151 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
543 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,160 points
299 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, 2020 in AWS by MD
• 95,160 points
226 views