VPC"handson-cli-lambda-vpc"のセキュリティグループ"handson-cli-lambda-sg"のIngressルールを確認します。
手順に必要な設定値を変数に格納をします。
0. リージョンの指定
リージョンを指定します。
環境変数の設定: export AWS_DEFAULT_REGION='ap-northeast-1'
環境変数の設定:
export AWS_DEFAULT_REGION='ap-northeast-1'
1. VPCのタグ名
VPCのタグ名を指定します。
変数の設定: EC2_VPC_TAG_NAME='handson-cli-lambda-vpc'
変数の設定:
EC2_VPC_TAG_NAME='handson-cli-lambda-vpc'
2. セキュリティグループ名
セキュリティグループ名を指定します。
変数の設定: EC2_SECURITY_GROUP_NAME='handson-cli-lambda-sg'
EC2_SECURITY_GROUP_NAME='handson-cli-lambda-sg'
各変数に正しい設定値が格納されていることを確認しながら保存します。
変数の確認: cat << END # 0. AWS_DEFAULT_REGION:"ap-northeast-1" AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" # 1. EC2_VPC_TAG_NAME:"handson-cli-lambda-vpc" EC2_VPC_TAG_NAME="${EC2_VPC_TAG_NAME}" # 2. EC2_SECURITY_GROUP_NAME:"handson-cli-lambda-sg" EC2_SECURITY_GROUP_NAME="${EC2_SECURITY_GROUP_NAME}" END
変数の確認:
cat << END # 0. AWS_DEFAULT_REGION:"ap-northeast-1" AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" # 1. EC2_VPC_TAG_NAME:"handson-cli-lambda-vpc" EC2_VPC_TAG_NAME="${EC2_VPC_TAG_NAME}" # 2. EC2_SECURITY_GROUP_NAME:"handson-cli-lambda-sg" EC2_SECURITY_GROUP_NAME="${EC2_SECURITY_GROUP_NAME}" END
下段の変数が入っていない、もしくは上段と同等の値が入っていない場合は、それぞれの手順番号に戻って変数の設定を行います。
VPC IDを取得します。
コマンド: EC2_VPC_ID=$( \ aws ec2 describe-vpcs \ --filters Name=tag:Name,Values=${EC2_VPC_TAG_NAME} \ --query 'Vpcs[].VpcId' \ --output text \ ) \ && echo ${EC2_VPC_ID} 結果(例): vpc-xxxxxxxxxxxxxxxxx
コマンド:
EC2_VPC_ID=$( \ aws ec2 describe-vpcs \ --filters Name=tag:Name,Values=${EC2_VPC_TAG_NAME} \ --query 'Vpcs[].VpcId' \ --output text \ ) \ && echo ${EC2_VPC_ID}
結果(例):
vpc-xxxxxxxxxxxxxxxxx
セキュリティグループIDを取得します。
コマンド: EC2_SECURITY_GROUP_ID=$( \ aws ec2 describe-security-groups \ --filter Name=vpc-id,Values=${EC2_VPC_ID} \ Name=group-name,Values=${EC2_SECURITY_GROUP_NAME} \ --query "SecurityGroups[].GroupId" \ --output text \ ) \ && echo ${EC2_SECURITY_GROUP_ID} 結果(例): sg-xxxxxxxxxxxxxxxxx
EC2_SECURITY_GROUP_ID=$( \ aws ec2 describe-security-groups \ --filter Name=vpc-id,Values=${EC2_VPC_ID} \ Name=group-name,Values=${EC2_SECURITY_GROUP_NAME} \ --query "SecurityGroups[].GroupId" \ --output text \ ) \ && echo ${EC2_SECURITY_GROUP_ID}
sg-xxxxxxxxxxxxxxxxx
Ingressルールを確認します。
コマンド: aws ec2 describe-security-groups \ --filter Name=group-id,Values=${EC2_SECURITY_GROUP_ID} \ --query 'SecurityGroups[].IpPermissions[]' 結果(例): []
aws ec2 describe-security-groups \ --filter Name=group-id,Values=${EC2_SECURITY_GROUP_ID} \ --query 'SecurityGroups[].IpPermissions[]'
[]
「VPC"handson-cli-lambda-vpc"にセキュリティグループ"handson-cli-lambda-sg"のIngressルールを確認できている。」ことを確認します。
注釈
主処理で取得できていればOKです