New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

serverless-dynamodb-autoscaling

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-dynamodb-autoscaling - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

2

package.json
{
"name": "serverless-dynamodb-autoscaling",
"description": "Serverless Plugin for Amazon DynamoDB Auto Scaling.",
"version": "0.3.2",
"version": "0.3.3",
"main": "src/plugin.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -12,6 +12,7 @@ const util = require('util')

function policyScale (table, read, index, stage) {
function policyScale (service, table, read, index, stage) {
return clean(
util.format(
'Table%sScalingPolicy-%s%s%s',
'%sTable%sScalingPolicy-%s%s%s',
service || '',
read ? 'Read' : 'Write',

@@ -25,6 +26,7 @@ table,

function policyRole (table, index, stage) {
function policyRole (service, table, index, stage) {
return clean(
util.format(
'DynamoDBAutoscalePolicy-%s%s%s',
'%sDynamoDBAutoscalePolicy-%s%s%s',
service || '',
table,

@@ -45,6 +47,7 @@ index || '',

function target (table, read, index, stage) {
function target (service, table, read, index, stage) {
return clean(
util.format(
'AutoScalingTarget%s-%s%s%s',
'%sAutoScalingTarget%s-%s%s%s',
service || '',
read ? 'Read' : 'Write',

@@ -67,6 +70,7 @@ table,

function role (table, index, stage) {
function role (service, table, index, stage) {
return clean(
util.format(
'DynamoDBAutoscaleRole-%s%s%s',
'%sDynamoDBAutoscaleRole-%s%s%s',
service || '',
table,

@@ -73,0 +77,0 @@ index || '',

const names = require('./names')
class Policy {
constructor (table, value, read, scaleIn, scaleOut, index, stage) {
constructor (service, table, value, read, scaleIn, scaleOut, index, stage) {
this.service = service
this.table = table

@@ -23,9 +24,9 @@ this.index = index

return {
[names.policyScale(this.table, this.read, this.index, this.stage)]: {
[names.policyScale(this.service, this.table, this.read, this.index, this.stage)]: {
'Type': 'AWS::ApplicationAutoScaling::ScalingPolicy',
'DependsOn': [ this.table, names.target(this.table, this.read, this.index, this.stage) ].concat(this.dependencies),
'DependsOn': [ this.table, names.target(this.service, this.table, this.read, this.index, this.stage) ].concat(this.dependencies),
'Properties': {
'PolicyName': names.policyScale(this.table, this.read, this.index, this.stage),
'PolicyName': names.policyScale(this.service, this.table, this.read, this.index, this.stage),
'PolicyType': 'TargetTrackingScaling',
'ScalingTargetId': { 'Ref': names.target(this.table, this.read, this.index, this.stage) },
'ScalingTargetId': { 'Ref': names.target(this.service, this.table, this.read, this.index, this.stage) },
'TargetTrackingScalingPolicyConfiguration': {

@@ -32,0 +33,0 @@ 'PredefinedMetricSpecification': {

const names = require('./names')
class Role {
constructor (table, index, stage) {
constructor (service, table, index, stage) {
this.service = service
this.table = table

@@ -19,7 +20,7 @@ this.index = index

return {
[names.role(this.table, this.index, this.stage)]: {
[names.role(this.service, this.table, this.index, this.stage)]: {
'Type': 'AWS::IAM::Role',
'DependsOn': [ this.table ].concat(this.dependencies),
'Properties': {
'RoleName': names.role(this.table, this.index, this.stage),
'RoleName': names.role(this.service, this.table, this.index, this.stage),
'AssumeRolePolicyDocument': {

@@ -39,3 +40,3 @@ 'Version': '2012-10-17',

{
'PolicyName': names.policyRole(this.table, this.index, this.stage),
'PolicyName': names.policyRole(this.service, this.table, this.index, this.stage),
'PolicyDocument': {

@@ -42,0 +43,0 @@ 'Version': '2012-10-17',

const names = require('./names')
class Target {
constructor (table, min, max, read, index, stage) {
constructor (service, table, min, max, read, index, stage) {
this.service = service
this.table = table

@@ -28,5 +29,5 @@ this.index = index

return {
[names.target(this.table, this.read, this.index, this.stage)]: {
[names.target(this.service, this.table, this.read, this.index, this.stage)]: {
'Type': 'AWS::ApplicationAutoScaling::ScalableTarget',
'DependsOn': [ this.table, names.role(this.table, this.index, this.stage) ].concat(this.dependencies),
'DependsOn': [ this.table, names.role(this.service, this.table, this.index, this.stage) ].concat(this.dependencies),
'Properties': {

@@ -36,3 +37,3 @@ 'MaxCapacity': this.max,

'ResourceId': { 'Fn::Join': [ '', resource ] },
'RoleARN': { 'Fn::GetAtt': [ names.role(this.table, this.index, this.stage), 'Arn' ] },
'RoleARN': { 'Fn::GetAtt': [ names.role(this.service, this.table, this.index, this.stage), 'Arn' ] },
'ScalableDimension': names.dimension(this.read, this.index),

@@ -39,0 +40,0 @@ 'ServiceNamespace': 'dynamodb'

@@ -39,2 +39,11 @@ const _ = require('lodash')

/**
* Get the current service name
*
* @return {string}
*/
getServiceName () {
return this.serverless.service.getServiceName()
}
/**
* Validate the request and check if configuration is available

@@ -85,2 +94,3 @@ */

const resources = []
const service = this.getServiceName()
const stage = this.getStage()

@@ -95,3 +105,3 @@ const data = this.defaults(config)

// Add role to manage Auto Scaling policies
resources.push(new Role(table, index, stage))
resources.push(new Role(service, table, index, stage))

@@ -102,4 +112,4 @@ // Only add Auto Scaling for read capacity if configuration set is available

// ScaleIn/ScaleOut values are fix to 60% usage
new Policy(table, data.read.usage, true, 60, 60, index, stage),
new Target(table, data.read.minimum, data.read.maximum, true, index, stage)
new Policy(service, table, data.read.usage, true, 60, 60, index, stage),
new Target(service, table, data.read.minimum, data.read.maximum, true, index, stage)
)

@@ -112,4 +122,4 @@ }

// ScaleIn/ScaleOut values are fix to 60% usage
new Policy(table, data.write.usage, false, 60, 60, index, stage),
new Target(table, data.write.minimum, data.write.maximum, false, index, stage)
new Policy(service, table, data.write.usage, false, 60, 60, index, stage),
new Target(service, table, data.write.minimum, data.write.maximum, false, index, stage)
)

@@ -116,0 +126,0 @@ }

@@ -15,7 +15,7 @@ const names = require('../../src/aws/names')

it('creates name for Role', () => {
expect(names.role('test-with-invalid-characters')).toBe('DynamoDBAutoscaleRoletestwithinvalidcharacters')
expect(names.role('service', 'test-with-invalid-characters')).toBe('serviceDynamoDBAutoscaleRoletestwithinvalidcharacters')
})
it('creates name for Role with index and stage', () => {
expect(names.role('test-with-invalid-characters', 'index', 'stage')).toBe('DynamoDBAutoscaleRoletestwithinvalidcharactersindexstage')
expect(names.role('service', 'test-with-invalid-characters', 'index', 'stage')).toBe('serviceDynamoDBAutoscaleRoletestwithinvalidcharactersindexstage')
})

@@ -40,20 +40,20 @@

it('creates name for PolicyRole', () => {
expect(names.policyRole('test-with-invalid-characters')).toBe('DynamoDBAutoscalePolicytestwithinvalidcharacters')
expect(names.policyRole('', 'test-with-invalid-characters')).toBe('DynamoDBAutoscalePolicytestwithinvalidcharacters')
})
it('creates name for PolicyScale (read)', () => {
expect(names.policyScale('test-with-invalid-characters', true)).toBe('TableReadScalingPolicytestwithinvalidcharacters')
expect(names.policyScale('', 'test-with-invalid-characters', true)).toBe('TableReadScalingPolicytestwithinvalidcharacters')
})
it('creates name for PolicyScale (write)', () => {
expect(names.policyScale('test-with-invalid-characters', false)).toBe('TableWriteScalingPolicytestwithinvalidcharacters')
expect(names.policyScale('', 'test-with-invalid-characters', false)).toBe('TableWriteScalingPolicytestwithinvalidcharacters')
})
it('creates name for Target (read)', () => {
expect(names.target('test-with-invalid-characters', true)).toBe('AutoScalingTargetReadtestwithinvalidcharacters')
expect(names.target('', 'test-with-invalid-characters', true)).toBe('AutoScalingTargetReadtestwithinvalidcharacters')
})
it('creates name for Target (write)', () => {
expect(names.target('test-with-invalid-characters', false)).toBe('AutoScalingTargetWritetestwithinvalidcharacters')
expect(names.target('', 'test-with-invalid-characters', false)).toBe('AutoScalingTargetWritetestwithinvalidcharacters')
})
})

@@ -6,13 +6,13 @@ const names = require('../../src/aws/names')

it('creates CF resource for read capacity', () => {
const p = new Policy('my-table-name', 0.75, true, 60, 70)
const p = new Policy('', 'my-table-name', 0.75, true, 60, 70)
const j = p.toJSON()
expect(j).toHaveProperty(names.policyScale('my-table-name', true))
expect(j).toHaveProperty(names.policyScale('', 'my-table-name', true))
const d = j[names.policyScale('my-table-name', true)]
const d = j[names.policyScale('', 'my-table-name', true)]
expect(d).toHaveProperty('Type', 'AWS::ApplicationAutoScaling::ScalingPolicy')
expect(d).toHaveProperty('Properties.PolicyName', names.policyScale('my-table-name', true))
expect(d).toHaveProperty('Properties.PolicyName', names.policyScale('', 'my-table-name', true))
expect(d).toHaveProperty('Properties.PolicyType', 'TargetTrackingScaling')
expect(d).toHaveProperty('Properties.ScalingTargetId', { 'Ref': names.target('my-table-name', true) })
expect(d).toHaveProperty('Properties.ScalingTargetId', { 'Ref': names.target('', 'my-table-name', true) })
expect(d).toHaveProperty('Properties.TargetTrackingScalingPolicyConfiguration.PredefinedMetricSpecification.PredefinedMetricType', names.metric(true))

@@ -28,13 +28,13 @@

it('creates CF resource for write capacity', () => {
const p = new Policy('my-table-name', 0.15, false, 60, 70)
const p = new Policy('', 'my-table-name', 0.15, false, 60, 70)
const j = p.toJSON()
expect(j).toHaveProperty(names.policyScale('my-table-name', false))
expect(j).toHaveProperty(names.policyScale('', 'my-table-name', false))
const d = j[names.policyScale('my-table-name', false)]
const d = j[names.policyScale('', 'my-table-name', false)]
expect(d).toHaveProperty('Type', 'AWS::ApplicationAutoScaling::ScalingPolicy')
expect(d).toHaveProperty('Properties.PolicyName', names.policyScale('my-table-name', false))
expect(d).toHaveProperty('Properties.PolicyName', names.policyScale('', 'my-table-name', false))
expect(d).toHaveProperty('Properties.PolicyType', 'TargetTrackingScaling')
expect(d).toHaveProperty('Properties.ScalingTargetId', { 'Ref': names.target('my-table-name', false) })
expect(d).toHaveProperty('Properties.ScalingTargetId', { 'Ref': names.target('', 'my-table-name', false) })
expect(d).toHaveProperty('Properties.TargetTrackingScalingPolicyConfiguration.PredefinedMetricSpecification.PredefinedMetricType', names.metric(false))

@@ -41,0 +41,0 @@

@@ -6,8 +6,8 @@ const names = require('../../src/aws/names')

it('creates CF resource', () => {
const r = new Role('my-table-name')
const r = new Role('', 'my-table-name')
const j = r.toJSON()
expect(j).toHaveProperty(names.role('my-table-name'))
expect(j).toHaveProperty(names.role('', 'my-table-name'))
const d = j[names.role('my-table-name')]
const d = j[names.role('', 'my-table-name')]

@@ -19,12 +19,14 @@ expect(d).toHaveProperty('Type', 'AWS::IAM::Role')

it('truncates role name if needed', () => {
const r = new Role('my-table-name-with-some-extra-long-string-information-added-to-the-end')
const r = new Role('service', 'my-table-name-with-some-extra-long-string-information-added-to-the-end')
const j = r.toJSON()
expect(j).toHaveProperty(names.role('my-table-name-with-some-extra-long-string-information-added-to-the-end'))
const n = 'serviceDynamoDBAutoscaleRolemyta941c3679150ea9fa409846dd3c00ec13'
const d = j[names.role('my-table-name-with-some-extra-long-string-information-added-to-the-end')]
expect(j).toHaveProperty(n)
const d = j[n]
expect(d.Properties.RoleName.length).toBe(64)
expect(d).toHaveProperty('Properties.RoleName', 'DynamoDBAutoscaleRolemytablename0cde19b63d7d9f9b35cd41a979fd72a2')
expect(d).toHaveProperty('Properties.RoleName', n)
})
})

@@ -6,8 +6,8 @@ const names = require('../../src/aws/names')

it('creates CF resource for read capacity', () => {
const t = new Target('my-table-name', 4, 100, true)
const t = new Target('', 'my-table-name', 4, 100, true)
const j = t.toJSON()
expect(j).toHaveProperty(names.target('my-table-name', true))
expect(j).toHaveProperty(names.target('', 'my-table-name', true))
const d = j[names.target('my-table-name', true)]
const d = j[names.target('', 'my-table-name', true)]

@@ -20,12 +20,12 @@ expect(d).toHaveProperty('Type', 'AWS::ApplicationAutoScaling::ScalableTarget')

expect(d).toHaveProperty('Properties.RoleARN.Fn::GetAtt')
expect(d).toHaveProperty('Properties.RoleARN.Fn::GetAtt', [ names.role('my-table-name'), 'Arn' ])
expect(d).toHaveProperty('Properties.RoleARN.Fn::GetAtt', [ names.role('', 'my-table-name'), 'Arn' ])
})
it('creates CF resource for write capacity', () => {
const t = new Target('my-table-name', 100, 2000, false)
const t = new Target('', 'my-table-name', 100, 2000, false)
const j = t.toJSON()
expect(j).toHaveProperty(names.target('my-table-name', false))
expect(j).toHaveProperty(names.target('', 'my-table-name', false))
const d = j[names.target('my-table-name', false)]
const d = j[names.target('', 'my-table-name', false)]

@@ -38,4 +38,4 @@ expect(d).toHaveProperty('Type', 'AWS::ApplicationAutoScaling::ScalableTarget')

expect(d).toHaveProperty('Properties.RoleARN.Fn::GetAtt')
expect(d).toHaveProperty('Properties.RoleARN.Fn::GetAtt', [ names.role('my-table-name'), 'Arn' ])
expect(d).toHaveProperty('Properties.RoleARN.Fn::GetAtt', [ names.role('', 'my-table-name'), 'Arn' ])
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc