Created
October 14, 2017 15:33
-
-
Save tilfin/c947c6923e707be37b2fa70c582d5240 to your computer and use it in GitHub Desktop.
AWSのIAMロール・ポリシーをソースコード管理するのに役立つツールライブラリ ref: http://qiita.com/tilfin/items/4e2157ebd7e761c31f82
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Role": { | |
"RoleName": "yourapp-ec2-api-ENV", | |
"Path": "/", | |
"AssumeRolePolicyDocument": { | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Principal": { | |
"Service": "ec2.amazonaws.com" | |
}, | |
"Action": "sts:AssumeRole" | |
} | |
] | |
} | |
}, | |
"AttachedPolicies": [ | |
{ | |
"PolicyName": "yourapp-s3-storage-ENV", | |
"PolicyArn": "arn:aws:iam::ACCOUNT_ID:policy/yourapp-s3-storage-ENV" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"s3:PutObject", | |
"s3:GetObject", | |
"s3:DeleteObject" | |
], | |
"Resource": "arn:aws:s3:::yourapp-storage-ENV/*" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install -g aws-iam-policy-tool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ awsiamtool export-role ./roles | |
$ awsiamtool export-policy ./policies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ awsiamtool validate-role -i 111122223333 -e dev roles | |
$ awsiamtool validate-policy -i 111122223333 -e dev policies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ AWS_PROFILE=prod awsiamtool import-policy -i 111122224444 -e prd policies | |
$ AWS_PROFILE=prod awsiamtool import-role -i 111122224444 -e prd roles |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const awsIamPolicyLib = require('aws-iam-policy-tool'); | |
const opts = { | |
json: true, | |
overwrite: true | |
}; | |
const varSets = { | |
ACCOUNT_ID: '000011112222', | |
ENV: 'stg', | |
COMMON_ACCOUNT_ID: '333344445555' | |
}; | |
awsIamPolicyLib.importPolicy('./policies', varSets, opts); | |
.then(() => { | |
return awsIamPolicyLib.importRole('./roles', varSets, opts); | |
}) | |
.then(() => { console.info('Importing done') }) | |
.catch(err => { console.error(err) }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment