Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add roleArn: config, support external IAM role. #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions src/aws/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ export default class Target extends Resource {

const nameTarget = this.name.target(this.read)
const nameRole = this.name.role()
const roleArn = this.options.roleArn
const nameDimension = this.name.dimension(this.read)

const DependsOn = [ this.options.table, nameRole ].concat(this.dependencies)
const DependsOn = [ this.options.table ].concat(this.dependencies)

let accessRoleArn: any = { 'Fn::GetAtt': [ nameRole, 'Arn' ] }

if (!!roleArn) {
accessRoleArn = `'${roleArn}'`
} else {
DependsOn.concat(nameRole)
}

return {
[nameTarget]: {
Expand All @@ -30,7 +39,7 @@ export default class Target extends Resource {
MaxCapacity: this.max,
MinCapacity: this.min,
ResourceId: { 'Fn::Join': [ '', resource ] },
RoleARN: { 'Fn::GetAtt': [ nameRole, 'Arn' ] },
RoleARN: accessRoleArn,
ScalableDimension: nameDimension,
ServiceNamespace: 'dynamodb'
},
Expand Down
10 changes: 7 additions & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ class AWSDBAutoScaling {
)

// Add role to manage Auto Scaling policies
const resources: any[] = [
new Role(options)
]
const resources: any[] = []

if (!config.roleArn) {
resources.push(new Role(options))
} else {
options.roleArn = config.roleArn
}

// Only add Auto Scaling for read capacity if configuration set is available
if (!!config.read) {
Expand Down
4 changes: 3 additions & 1 deletion vendor/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare interface Capacity {
table: string | string[]
index: string | string[]
indexOnly?: boolean
roleArn?: string
write?: CapacityConfiguration
read?: CapacityConfiguration
}
Expand All @@ -18,6 +19,7 @@ declare interface Options {
service: string
stage: string
table: string
roleArn?: string
}

/**
Expand All @@ -29,4 +31,4 @@ declare namespace Serverless {
capacities: Capacity[]
}
}
}
}