Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Simplify deployRole a bit #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions src/deployRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ const updateRole = async (config, params = {}) => {

const res = await iam.getRole({ RoleName: params.roleName }).promise()

if (!params.assumeRolePolicyDocument) {
params.assumeRolePolicyDocument = {
Version: '2012-10-17',
Statement: {
Effect: 'Allow',
Principal: {
Service: params.service
},
Action: 'sts:AssumeRole'
}
}
}

await iam
.updateAssumeRolePolicy({
RoleName: params.roleName,
Expand All @@ -76,19 +63,6 @@ const updateRole = async (config, params = {}) => {
const createRole = async (config, params = {}) => {
const iam = new AWS.IAM(config)

if (!params.assumeRolePolicyDocument) {
params.assumeRolePolicyDocument = {
Version: '2012-10-17',
Statement: {
Effect: 'Allow',
Principal: {
Service: params.service
},
Action: 'sts:AssumeRole'
}
}
}

const res = await iam
.createRole({
RoleName: params.roleName,
Expand All @@ -111,12 +85,20 @@ module.exports = async (config, params = {}) => {
throw new Error(`Missing "roleName" param.`)
}

params.service = params.service || 'lambda.amazonaws.com'
params.policy = params.policy || 'arn:aws:iam::aws:policy/AdministratorAccess'

// assumeRolePolicyDocument should cancel out "service"
if (params.assumeRolePolicyDocument) {
params.service = null
if (!params.assumeRolePolicyDocument) {
params.assumeRolePolicyDocument = {
Version: '2012-10-17',
Statement: {
Effect: 'Allow',
Principal: {
Service: params.service || 'lambda.amazonaws.com'
},
Action: 'sts:AssumeRole'
}
}
}

try {
Expand Down