Skip to content

Instantly share code, notes, and snippets.

@tilfin
Created October 14, 2017 15:33
Show Gist options
  • Save tilfin/c947c6923e707be37b2fa70c582d5240 to your computer and use it in GitHub Desktop.
Save tilfin/c947c6923e707be37b2fa70c582d5240 to your computer and use it in GitHub Desktop.
AWSのIAMロール・ポリシーをソースコード管理するのに役立つツールライブラリ ref: http://qiita.com/tilfin/items/4e2157ebd7e761c31f82
{
"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"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::yourapp-storage-ENV/*"
}
]
}
$ npm install -g aws-iam-policy-tool
$ awsiamtool export-role ./roles
$ awsiamtool export-policy ./policies
$ awsiamtool validate-role -i 111122223333 -e dev roles
$ awsiamtool validate-policy -i 111122223333 -e dev policies
$ AWS_PROFILE=prod awsiamtool import-policy -i 111122224444 -e prd policies
$ AWS_PROFILE=prod awsiamtool import-role -i 111122224444 -e prd roles
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