안녕하세요. 코미야입니다.
이번에는 그룹 파일의 규칙을 piculet으로 업데이트하는 것이 아닙니다. 조금 정리하거나 삭제하고 싶지만, 수동으로 하기에는 너무 번거롭고, 연산 미스가 걱정되며, 시간이 많이 걸리고, 빨리 집에 가고 싶습니다. 그래서 어떤 규칙이 모두 연결되는지 한 번에 확인하거나 대량으로 업데이트하고 싶다면 for 루프와 CLI를 사용하는 방법이 있습니다. SecurityGroup 상한선 완화를 신청할 때는 SG 작성 과정에서 통신 성능이 걸릴 때 이런 작업을 해야 합니다.
저는 잘 쓰는 사람이 아니지만, 일단 올릴게요. 사용은 본인 책임 하에 사용해 주세요. 비슷한 일을 하고 더 정교한 방법을 아는 분들이 많아 보입니다. 이나다 씨와 협력팀 다른 멤버들이 우리 회사에 더 익숙하다고 느낍니다. 마사카리가 환영합니다. 이나다 씨에게 부탁했을 때, 텍스트에서 조인을 더 많이 쓰라고 해서 곧 뭔가 쓸 것 같아요.
SecurityGroup ID와 연결된 인스턴스 정보 획득
기존 정보만 받고 업데이트하지 않기 때문에 쉽게 할 수 있을 것 같습니다. 먼저, 리스트를 만드세요(삭제하고 싶은 SG를 입력하세요).
vi 리스트파일
SG-xxxxxxxx,SG_hoge_dev1
SG-이이SG_fuga_dev2
...
list=listfile
프로필=xxxx
리스트를 불러오고 describe-instance를 실행하세요
'캣 $list|그렙 -V 엘브'에서 나를 위해
해야 할
Groupid='echo $i |awk -F, '{print $1}''
Groupname='echo $i |awk -F, '{print $2}''
에코 $i
AWS EC2 describe-instances --profile ${profile} --filters Name=instance.group-id,Values=$groupid --output text \
--쿼리 '예약[]. 인스턴스[*]. [인스턴스ID, PrivateIpAddress, 태그[? 키=='Name']. 값[]]' --출력 json \
|sed -e '/\]/d' -e '/\[/d' -e '/^$/d' -e 's/ //g'|perl -pe 's/,[ ]*\n/,/g'|정렬 -t , -k 3
메아리 ""
끝났어
결과에서 리스트 파일을 생성하고 SG를 제거하거나 교체하는 데 사용됩니다.
SecurityGroup ID와 연동된 ELB 정보 획득
'캣 $list'의 나를 위해서요
해야 할
Groupid='echo $i |awk -F, '{print $1}''
Groupname='echo $i |awk -F, '{print $2}''
에코 $i
AWS ELB Describe-Load-Balancers --profile ${profile} \
--쿼리 'LoadBalancerDescriptions[*]. [LoadBalancerName,SecurityGroups]' --output=json \
|sed -e 's/\[//g' -e 's/\],//g' -e 's/\]//g' -e 's/ /g'|perl -pe "s/n/,/g" \
|sed -e '/^$/d'|perl -pe 's/,\n/,/g'|grep $groupid
메아리 ""
끝났어
결과에서 리스트 파일을 생성하고 SG를 제거하거나 교체하는 데 사용됩니다.
인스턴스의 보안그룹을 특정 보안그룹으로 변경합니다
사용하시길 본인 책임 하에 사용해 주세요.
목록=xxxxx
'cat $list|grep -v xxxxx'에서 I
해야 할
instanceid='echo $i|awk -F, '{print $1}'|sed -e 's/"//g'''
attached_groups='AWS EC2 describe-instance-attribute --instance-id ${instanceid} --attribute groupSet --profile ${profile} --output=text|grep GROUPS|awk '{print $2}'|perl -pe 's/\n/ /g''
add_groupid="SG-xxxxxxxx"
Groupids='echo ${add_groupid}'
에코 $i
에코 "Curgroupids: ${attached_groups}"
echo "NewGroupIDS: ${GroupIDS}"
AWS EC2 modify-instance-attribute --instance-id ${instanceid} --groups ${groupids} --profile ${profile} --no-dry-run
에코 "결과:"
AWS EC2 describe-instance-attribute --instance-id ${instanceid} --attribute groupSet --profile ${profile} --output=text|grep GROUPS|awk '{print $2}'
메아리 ""
끝났어
*현재 상황만 확인하고 싶다면, modify-instance-attribute 라인을 제거하고 실행해 주세요. 적절한 경우 리터럴 문자열을 변경해 주세요.
인스턴스의 보안그룹에서 특정 보안그룹을 제거함
'cat $list|grep xxxxxxx'에 있는 I를 위해
해야 할
instanceid='echo $i|awk -F, '{print $1}'|sed -e 's/"//g'''
attached_groups='AWS EC2 describe-instance-attribute --instance-id ${instanceid} --attribute groupSet --profile ${profile} --output=text|grep GROUPS|awk '{print $2}'|perl -pe 's/\n/ /g''
Groupids='echo ${attached_groups}|sed -e 's/sg-aaa//g'|tr -s ' ''
에코 $i
에코 "Curgroupids: ${attached_groups}"
echo "NewGroupIDS: ${GroupIDS}"
AWS EC2 modify-instance-attribute --instance-id ${instanceid} --groups ${groupids} --profile ${profile} --no-dry-run
에코 "결과:"
AWS EC2 describe-instance-attribute --instance-id ${instanceid} --attribute groupSet --profile ${profile} --output=text|grep GROUPS|awk '{print $2}'
메아리 ""
끝났어
*현재 상황만 확인하고 싶다면, modify-instance-attribute 라인을 제거하고 실행해 주세요. 적절한 경우 리터럴 문자열을 변경해 주세요.
ELB의 보안 그룹을 특정 보안 그룹으로 변경합니다
'캣 $list|그렙 엘브'에서 나는
해야 할
elbname='echo $i|awk -F, '{print $1}'|sed -e 's/"//g'''
add_groupid="sg-bbbbbbbb"
에코 $elbname
current_groups='AWS ELB Describe-Load-Balancers --profile ${profile} --load-balancer-names ${elbname} --query 'LoadBalancerDescriptions[*]. [LoadBalancerName,SecurityGroups]' --output=text|grep sg-|sed -e 's/\t/ /''
NewGroupIds='echo ${add_groupid}'
에코 "커그룹ID: ${current_groups}"
echo "NewGroupID: ${NewGroupID}"
AWS ELB Apply-Security-Groups-to-Load-Balancer --load-Balancer-Name ${elbName} --security-groups ${newgroupids} --profile ${profile}
에코 "결과:"
AWS ELB describe-load-balancers --profile ${profile} --load-balancer-names ${elbname} --query 'LoadBalancerDescriptions[*]. [LoadBalancerName,SecurityGroups]' --output=text|grep sg-
메아리 ""
끝났어
*현재 상황만 확인하고 싶다면, apply-security-groups-to-load-balancer에서 해당 줄을 체크 해제하고 실행해 주세요. 적절한 경우 문자 그대로의 문자열을 변경해 주세요.
ELB의 보안 그룹에서 특정 보안 그룹을 제거하기
'캣 $list|그렙 엘브'에서 나는
해야 할
elbname='echo $i|awk -F, '{print $1}'|sed -e 's/"//g'''
에코 $elbname
current_groups='AWS ELB Describe-Load-Balancers --profile ${profile} --load-balancer-names ${elbname} --query 'LoadBalancerDescriptions[*]. [LoadBalancerName,SecurityGroups]' --output=text|grep sg-|sed -e 's/\t/ /''
NewGroupIds='echo ${current_groups}|sed -e 's/sg-cccccccc//g'|tr -s ' ''
에코 "커그룹ID: ${current_groups}"
echo "NewGroupID: ${NewGroupID}"
AWS ELB Apply-Security-Groups-to-Load-Balancer --load-Balancer-Name ${elbName} --security-groups ${newgroupids} --profile ${profile}
에코 "결과:"
AWS ELB describe-load-balancers --profile ${profile} --load-balancer-names ${elbname} --query 'LoadBalancerDescriptions[*]. [LoadBalancerName,SecurityGroups]' --output=text|grep sg-
메아리 ""
끝났어
*현재 상황만 확인하고 싶다면, apply-security-groups-to-load-balancer에서 해당 줄을 삭제하고 실행해 주세요. 필요에 따라 문자 그대로의 문자열을 변경해 주세요. 만약 이해가 안 된다면, 도움을 받을 수 있는 지점까지 파이프로 연결하고, 전달하는 부분을 잘라내어 실행 결과를 보는 것이 좋을 것 같습니다. AWS elb describe-load-balancers help를 입력하면 매뉴얼이 표시됩니다.
시청해 주셔서 감사합니다.