Skip to content

Instantly share code, notes, and snippets.

@tomotake-koike
Created December 10, 2020 05:42
Show Gist options
  • Select an option

  • Save tomotake-koike/834e32c63b48aa3da3bec9571f57a6ed to your computer and use it in GitHub Desktop.

Select an option

Save tomotake-koike/834e32c63b48aa3da3bec9571f57a6ed to your computer and use it in GitHub Desktop.
AWS configserviceでAWS resourceの設定情報を収集する

awscliからAWS Configをたたいてリソースタイプでリソース情報を収集する

Cloud9 IDEだとjqが無いのでセットアップ

(pythonは入っているのでスクリプトやってもいいのだけれど…。)

curl -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod 755 jq
jq_path=./jq

AWS Configで引っこ抜く

resource_type="AWS::EC2::Instance"
instances=$(aws configservice list-discovered-resources --resource-type ${resource_type} | ${jq_path} -r '.resourceIdentifiers[].resourceId')
for i in $instances
do
  aws configservice get-resource-config-history --resource-type ${resource_type} --limit 1 --resource-id $i | ${jq_path} -r '.configurationItems[].configuration' 
done > result-${resource_type}.json

Troubleshoot: Cloud9 IDEで作業している最中Token Expiredのエラーに見舞われたら

Cloud9のWebUI Terminalがどうも手になじまないので外部からSSHして動かしているからかもだが、こんなエラーにちょくちょく遭遇する。

An error occurred (ExpiredTokenException) when calling the ListDiscoveredResources operation: The security token included in the request is expired

こういう場合は、マネジメントコンソールからCloud9 IDEにアクセスしてOpen IDEする。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment