Follow dba-ninja.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

dba-ninja.com Links

Dba_db2_button

Sqlserver_dba_button

How do I create a security group in AWS command line?

14 November,2022 by Rambler

Question: I want to create security group for my AWS Instance . The idea is to associate the security group with an RDS Instance , and attach some ingress rules bound to a port 

 

Answer: Find a sequence of AWS CLI commands , which will take you through  the steps of : 

1) Identify the vpc id

2) Create the security group , using the vpc id from step 1

3) Add ingress rules

4) View the new security group rules

5) Delete the security group

You can use this sequence of AWS CLI commands to create some variables and add some automation  

--STEP1 : GET vpcid for the account. There should only be 1 vpcid. Make a note of the vpc-id
aws ec2 describe-vpcs --query "Vpcs[*].{VpcId:VpcId}" --output text

--STEP 2 : create new security group . make a note of the security group id 
aws ec2 create-security-group --group-name  my_db-access --description "rules for my_db_access" --vpc-id  REPLACE_WITH_VPC_ID
aws ec2 create-tags --resources REPLACE_WITH_NEW_SECURITY_GROUP_ID --tags Key=Name,Value=my_db-access

--STEP 3: add ingress rules 
aws ec2 authorize-security-group-ingress --group-id REPLACE_WITH-SECURITY_GROUP_ID --protocol tcp --port REPLACE_WITH_PORT --cidr REPLACE_WITH_IP_RANGE

aws ec2 authorize-security-group-ingress --group-id REPLACE_WITH-SECURITY_GROUP_ID --protocol tcp --port REPLACE_WITH_PORT --cidr REPLACE_WITH_IP_RANGE




STEP 4 : VIEW the new security group details
aws ec2 describe-security-groups --group-id REPLACE_WITH-SECURITY_GROUP_ID


EXTRA:   ONLY USE THIS COMMAND if deleting the security group. If the security group is attached to a resource it won't delete 
--delete security groups 
aws ec2 delete-security-group --group-id REPLACE_WITH-SECURITY_GROUP_ID




AWS CLI Cheatsheet


Author: Rambler (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How do I create a security group in AWS command line?


dba-ninja.com