Skip to content

Instantly share code, notes, and snippets.

@onigra
Last active August 29, 2015 14:17
Show Gist options
  • Save onigra/060877faa60e29f2c07f to your computer and use it in GitHub Desktop.
Save onigra/060877faa60e29f2c07f to your computer and use it in GitHub Desktop.
特定のセキュリティグループのInboundの追加と削除のみができるIAM policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:AuthorizeSecurityGroupIngress",
"ec2:RevokeSecurityGroupIngress"
],
"Resource": [
"arn:aws:ec2:ap-northeast-1:12345:security-group/sg-example"
]
}
]
}
#!/bin/bash
global_ip=$(curl -s inet-ip.info)
# IP制限追加
aws ec2 authorize-security-group-ingress --group-id $SG_GROUP_ID --protocol tcp --port 80 --cidr "$global_ip/32"
aws ec2 authorize-security-group-ingress --group-id $SG_GROUP_ID --protocol tcp --port 443 --cidr "$global_ip/32"
# IP制限削除
aws ec2 revoke-security-group-ingress --group-id $SG_GROUP_ID --protocol tcp --port 80 --cidr "$global_ip/32"
aws ec2 revoke-security-group-ingress --group-id $SG_GROUP_ID --protocol tcp --port 443 --cidr "$global_ip/32"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment