From 8cd3064a01e666919d0c6510c5ceb741489c0646 Mon Sep 17 00:00:00 2001 From: "shawn.kovalchick" Date: Wed, 14 Jun 2017 15:37:29 -0400 Subject: [PATCH 1/5] Add handling for index provisioning --- .gitignore | 4 +- scaler.properties | 22 ++++-- .../lambdadynamodbscaler/Scaler.java | 76 +++++++++++++++++-- 3 files changed, 88 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 70b31f5..1767a18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *desktop.ini *.jar .netbeans* -target/*/ \ No newline at end of file +target/*/ +/.idea +*.iml \ No newline at end of file diff --git a/scaler.properties b/scaler.properties index 9e15322..0f6ae05 100644 --- a/scaler.properties +++ b/scaler.properties @@ -1,22 +1,28 @@ tablenames=example_scaler,example_scaler2 +indexnames=example_scaler%index_one #Table 1, changes 4 times per day # from 01 to 07 - Low usage 01.example_scaler.read=2 01.example_scaler.write=2 #from 07 to 09 - Medium usage -05.example_scaler.read=6 -05.example_scaler.write=6 -#from 09 to 18 - High usage -07.example_scaler.read=20 -07.example_scaler.write=20 -#from 18 to 01 - Medium usage 07.example_scaler.read=6 07.example_scaler.write=6 +#from 09 to 18 - High usage +09.example_scaler.read=20 +09.example_scaler.write=20 +#from 18 to 01 - Medium usage +18.example_scaler.read=6 +18.example_scaler.write=6 - +#Table 1 Index 1 changes 2 times per day +#Index only has usage between 7 and 9 +07.example_scaler%index_one.read=6 +07.example_scaler%index_one.write=6 +09.example_scaler%index_one.read=1 +09.example_scaler%index_one.write=1 #Table 2, changes 2 times per day -#Table only as usage between 6 and 8 +#Table only has usage between 6 and 8 05.example_scaler2.read=10 05.example_scaler2.write=10 09.example_scaler2.read=1 diff --git a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java index 2ca9fee..16be0a6 100644 --- a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java +++ b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java @@ -6,6 +6,7 @@ import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Table; +import com.amazonaws.services.dynamodbv2.model.GlobalSecondaryIndexDescription; import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; import com.amazonaws.services.dynamodbv2.model.TableDescription; import com.amazonaws.services.lambda.runtime.Context; @@ -63,21 +64,60 @@ public Response scale(Object input, Context context) if (ScalingProperties.containsKey(readProp) && ScalingProperties.containsKey(writeProp)) { - String readCapacity = (String) ScalingProperties.getProperty(readProp); - String writeCapacity = (String) ScalingProperties.getProperty(writeProp); + String readCapacity = ScalingProperties.getProperty(readProp); + String writeCapacity = ScalingProperties.getProperty(writeProp); //Execute the scaling change message += scaleTable(tableName, Long.parseLong(readCapacity), Long.parseLong(writeCapacity)); } else { - log("No values found for table " + tableName ); - message += "\nNo values found for table " + tableName + "\n"; + log(tableName + "\n No values found for table.\n"); + message += tableName + "\n No values found for table.\n"; } } } else { - log("tables parameter not found in properties file"); + log("tableNames parameter not found in properties file"); + } + //Get the index names + if (ScalingProperties.containsKey("indexnames")) + { + String value = (String) ScalingProperties.get("indexnames"); + String[] tableAndIndexNames = value.split(","); + for (String tableAndIndexName : tableAndIndexNames) + { + String[] split = tableAndIndexName.split("%"); + if (split.length == 2) + { + String tableName = split[0]; + String indexName = split[1]; + //Check if there is a change requested for this hour + String readProp = hour + "." + indexName + ".read"; + String writeProp = hour + "." + indexName + ".write"; + if (ScalingProperties.containsKey(readProp) + && ScalingProperties.containsKey(writeProp)) + { + String readCapacity = ScalingProperties.getProperty(readProp); + String writeCapacity = ScalingProperties.getProperty(writeProp); + //Execute the scaling change + message += scaleIndex(tableName, indexName, Long.parseLong(readCapacity), Long.parseLong(writeCapacity)); + } + else + { + log("No values found for index " + tableAndIndexName); + message += "\nNo values found for index " + tableAndIndexName + "\n"; + } + } + else + { + message += tableAndIndexName + "\n Index name in wrong format (tableName:indexName).\n"; + } + } + } + else + { + log("indexNames parameter not found in properties file"); } log(message); Response response = new Response(true, message); @@ -119,6 +159,32 @@ private String scaleTable(String tableName, Long readCapacity, Long writeCapacit return tableName + "\n Requested throughput equals current throughput\n"; } } + + private String scaleIndex(String tableName, String indexName, Long readCapacity, Long writeCapacity) + { + Table table = dynamoDB.getTable(tableName); + ProvisionedThroughput tp = new ProvisionedThroughput(); + tp.setReadCapacityUnits(readCapacity); + tp.setWriteCapacityUnits(writeCapacity); + TableDescription d = table.describe(); + for (GlobalSecondaryIndexDescription indexDescription : d.getGlobalSecondaryIndexes()) { + if (Objects.equals(indexDescription.getIndexName(), indexName)) { + if (!Objects.equals(indexDescription.getProvisionedThroughput().getReadCapacityUnits(), readCapacity) + || !Objects.equals(indexDescription.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity)) { + d = table.getIndex(indexName).updateGSI(tp); + return tableName + ":" + indexName + "\nRequested read/write : " + readCapacity + "/" + writeCapacity + + "\nCurrent read/write :" + d.getProvisionedThroughput().getReadCapacityUnits() + "/" + d.getProvisionedThroughput().getWriteCapacityUnits() + + "\nStatus : " + d.getTableStatus() + "\n"; + } + else + { + return tableName + ":" + indexName + "\n Requested throughput equals current throughput.\n"; + } + } + } + return tableName + ":" + indexName + "\n No index found.\n"; + } + private void setup() { //Setup credentials From 9e6e23209020a6c74c642a0756a715ae4d30a930 Mon Sep 17 00:00:00 2001 From: John Lemp Date: Thu, 15 Jun 2017 10:09:41 -0400 Subject: [PATCH 2/5] add serverless based stack creation and deploy --- .gitignore | 8 +- README.md | 12 ++ pom.xml | 14 +-- serverless.yml | 60 +++++++++ .../lambdadynamodbscaler/Scaler.java | 114 ++++++++---------- 5 files changed, 135 insertions(+), 73 deletions(-) create mode 100644 serverless.yml diff --git a/.gitignore b/.gitignore index 70b31f5..72715f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,10 @@ *desktop.ini *.jar .netbeans* -target/*/ \ No newline at end of file +target/*/ +*~ +.DS_Store +.idea +*.swp +*.swo +*.iml \ No newline at end of file diff --git a/README.md b/README.md index a7d597e..c664181 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,15 @@ An AWS Lambda function to scale DynamoDB tables on an hourly schedule More info can be found here : https://medium.com/@quodlibet_be/using-aws-lambda-scheduled-tasks-to-scale-dynamodb-c65a336aca4f + + + +To deploy with Serverless : http://serverless.com + + npm install -g serverless + + sls deploy + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0553e8d..f304e42 100644 --- a/pom.xml +++ b/pom.xml @@ -7,30 +7,30 @@ jar UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 com.amazonaws aws-java-sdk-dynamodb - 1.10.16 + 1.11.147 com.amazonaws aws-java-sdk-cloudwatch - 1.10.16 + 1.11.147 com.amazonaws aws-lambda-java-core - 1.0.0 + 1.1.0 junit junit - 4.10 + 4.12 test @@ -42,7 +42,7 @@ 2.3 false - uber-${artifactId}-${version} + uber-${project.artifactId}-${project.version} diff --git a/serverless.yml b/serverless.yml new file mode 100644 index 0000000..085bfa7 --- /dev/null +++ b/serverless.yml @@ -0,0 +1,60 @@ +service: lambdaDynamodbScaler + +frameworkVersion: ">=1.2.0 <2.0.0" + +custom: + myStage: ${opt:stage, self:provider.stage} + jarPath: target/uber-LambdaDynamoDBScaler-1.0-SNAPSHOT.jar + bucket: my-bucket-lambda-dynamodb-scaler-{self:custom.myStage} + dev: + region: us-east-1 + prod: + region: us-east-1 + + +provider: + name: aws + stage: dev + runtime: java8 + region: ${self:custom.${self:custom.myStage}.region} + environment: + STAGE: ${self:custom.myStage} + BUCKET: ${self:custom.bucket} + iamRoleStatements: + - Effect: Allow + Action: + - logs:CreateLogGroup + - logs:CreateLogStream + - logs:PutLogEvents + Resource: "*" + - Effect: Allow + Action: + - dynamodb:ListTables + - dynamodb:DescribeTable + - dynamodb:UpdateTable + Resource: "*" + - Effect: Allow + Action: + - s3:GetObject + Resource: arn:aws:s3:::${self:custom.bucket}/* + +package: + artifact: ${self:custom.jarPath} + +functions: + scaler: + handler: be.quodlibet.lambdadynamodbscaler.Scaler::scale + memorySize: 128 + timeout: 30 + events: + - schedule: rate(1 hour) + +resources: + Resources: + ## Specifying the S3 Bucket + ConfigS3Bucket: + Type: AWS::S3::Bucket + Properties: + BucketName: ${self:custom.bucket} + VersioningConfiguration: + Status: Enabled \ No newline at end of file diff --git a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java index 2ca9fee..30f6f59 100644 --- a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java +++ b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java @@ -1,6 +1,6 @@ package be.quodlibet.lambdadynamodbscaler; -import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; @@ -15,33 +15,32 @@ import com.amazonaws.services.s3.model.GetObjectRequest; import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3ObjectInputStream; + import java.io.IOException; import java.util.Calendar; import java.util.Objects; +import java.util.Optional; import java.util.Properties; /** - * * @author Dries Horions */ -public class Scaler -{ - private static final String access_key_id = "ACCESSKEY"; - private static final String secret_access_key = "SECRET"; - private static final String configBucketName = "BUCKETNAME"; +public class Scaler { + // private static final String access_key_id = "ACCESSKEY"; + // private static final String secret_access_key = "SECRET"; + private static final String configBucketName = Optional.ofNullable(System.getenv("BUCKETNAME")).orElse("default-bucket-name-replace"); private static final String configKey = "scaler.properties"; - private static final Regions region = Regions.EU_WEST_1; + private static final Regions region = Regions + .fromName(Optional.ofNullable(System.getenv("AWS_DEFAULT_REGION")).orElse("us-east-1")); - private BasicAWSCredentials awsCreds; private Properties ScalingProperties; private AmazonS3 s3Client; private AmazonDynamoDBClient clnt; private DynamoDB dynamoDB; private LambdaLogger log; - public Response scale(Object input, Context context) - { - if (context != null) - { + + public Response scale(Object input, Context context) { + if (context != null) { log = context.getLogger(); } setup(); @@ -51,105 +50,90 @@ public Response scale(Object input, Context context) String message = "Scaling for hour : " + hour + "\n"; log(message); //Get the table names - if (ScalingProperties.containsKey("tablenames")) - { + if (ScalingProperties.containsKey("tablenames")) { String value = (String) ScalingProperties.get("tablenames"); String[] tableNames = value.split(","); - for (String tableName : tableNames) - { + for (String tableName : tableNames) { //Check if there is a change requested for this hour String readProp = hour + "." + tableName + ".read"; String writeProp = hour + "." + tableName + ".write"; - if (ScalingProperties.containsKey(readProp) - && ScalingProperties.containsKey(writeProp)) - { + if (ScalingProperties.containsKey(readProp) && ScalingProperties.containsKey(writeProp)) { String readCapacity = (String) ScalingProperties.getProperty(readProp); String writeCapacity = (String) ScalingProperties.getProperty(writeProp); //Execute the scaling change message += scaleTable(tableName, Long.parseLong(readCapacity), Long.parseLong(writeCapacity)); - } - else - { - log("No values found for table " + tableName ); + } else { + log("No values found for table " + tableName); message += "\nNo values found for table " + tableName + "\n"; } } - } - else - { + } else { log("tables parameter not found in properties file"); } log(message); Response response = new Response(true, message); return response; } + /** * Ensure we can also test this locally without context + * * @param message */ - private void log(String message) - { - if (log != null) - { + private void log(String message) { + if (log != null) { log.log(message); - } - else - { + } else { System.out.println(message); } } - private String scaleTable(String tableName, Long readCapacity, Long writeCapacity) - { + private String scaleTable(String tableName, Long readCapacity, Long writeCapacity) { Table table = dynamoDB.getTable(tableName); ProvisionedThroughput tp = new ProvisionedThroughput(); tp.setReadCapacityUnits(readCapacity); tp.setWriteCapacityUnits(writeCapacity); TableDescription d = table.describe(); - if (!Objects.equals(d.getProvisionedThroughput().getReadCapacityUnits(), readCapacity) - || !Objects.equals(d.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity)) - { + if (!Objects.equals(d.getProvisionedThroughput().getReadCapacityUnits(), readCapacity) || !Objects + .equals(d.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity)) { d = table.updateTable(tp); - return tableName + "\nRequested read/write : " + readCapacity + "/" + writeCapacity - + "\nCurrent read/write :" + d.getProvisionedThroughput().getReadCapacityUnits() + "/" + d.getProvisionedThroughput().getWriteCapacityUnits() - + "\nStatus : " + d.getTableStatus() + "\n"; - } - else - { + return tableName + + "\nRequested read/write : " + + readCapacity + + "/" + + writeCapacity + + "\nCurrent read/write :" + + d.getProvisionedThroughput().getReadCapacityUnits() + + "/" + + d.getProvisionedThroughput().getWriteCapacityUnits() + + "\nStatus : " + + d.getTableStatus() + + "\n"; + } else { return tableName + "\n Requested throughput equals current throughput\n"; } } - private void setup() - { - //Setup credentials - if (awsCreds == null) - { - awsCreds = new BasicAWSCredentials(access_key_id, secret_access_key); - } + + private void setup() { + //Setup S3 client - if (s3Client == null) - { - s3Client = new AmazonS3Client(awsCreds); + if (s3Client == null) { + s3Client = new AmazonS3Client(); } //Setup DynamoDB client - if (clnt == null) - { - clnt = new AmazonDynamoDBClient(awsCreds); + if (clnt == null) { + clnt = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain()); dynamoDB = new DynamoDB(clnt); clnt.setRegion(Region.getRegion(region)); } //Load properties from S3 - if (ScalingProperties == null) - { - try - { + if (ScalingProperties == null) { + try { ScalingProperties = new Properties(); S3Object object = s3Client.getObject(new GetObjectRequest(configBucketName, configKey)); S3ObjectInputStream stream = object.getObjectContent(); ScalingProperties.load(stream); - } - catch (IOException ex) - { + } catch (IOException ex) { log("Failed to read config file : " + configBucketName + "/" + configKey + "(" + ex.getMessage() + ")"); } } From f1924c5db3baaccf4fd9a15119e4ce8076bf4988 Mon Sep 17 00:00:00 2001 From: "shawn.kovalchick" Date: Thu, 15 Jun 2017 14:54:31 -0400 Subject: [PATCH 3/5] Fix formatting and merge changes --- README.md | 6 +- .../lambdadynamodbscaler/Scaler.java | 105 ++++++++++-------- 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index c664181..6286a24 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # lambdaDynamodbScaler -An AWS Lambda function to scale DynamoDB tables on an hourly schedule +An AWS Lambda function to scale DynamoDB tables and global secondary indexes on an hourly schedule - -More info can be found here : https://medium.com/@quodlibet_be/using-aws-lambda-scheduled-tasks-to-scale-dynamodb-c65a336aca4f +More info can be found +[here](https://medium.com/@quodlibet_be/using-aws-lambda-scheduled-tasks-to-scale-dynamodb-c65a336aca4f). diff --git a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java index 53267e8..8ba2c55 100644 --- a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java +++ b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java @@ -26,13 +26,17 @@ /** * @author Dries Horions */ -public class Scaler { - // private static final String access_key_id = "ACCESSKEY"; - // private static final String secret_access_key = "SECRET"; - private static final String configBucketName = Optional.ofNullable(System.getenv("BUCKETNAME")).orElse("default-bucket-name-replace"); +public class Scaler +{ + private static final String configBucketName = Optional + .ofNullable(System.getenv("BUCKETNAME")) + .orElse("default-bucket-name-replace"); private static final String configKey = "scaler.properties"; - private static final Regions region = Regions - .fromName(Optional.ofNullable(System.getenv("AWS_DEFAULT_REGION")).orElse("us-east-1")); + private static final Regions region = Regions.fromName( + Optional + .ofNullable(System.getenv("AWS_DEFAULT_REGION")) + .orElse("us-east-1") + ); private Properties ScalingProperties; private AmazonS3 s3Client; @@ -40,8 +44,10 @@ public class Scaler { private DynamoDB dynamoDB; private LambdaLogger log; - public Response scale(Object input, Context context) { - if (context != null) { + public Response scale(Object input, Context context) + { + if (context != null) + { log = context.getLogger(); } setup(); @@ -51,15 +57,17 @@ public Response scale(Object input, Context context) { String message = "Scaling for hour : " + hour + "\n"; log(message); //Get the table names - if (ScalingProperties.containsKey("tablenames")) { + if (ScalingProperties.containsKey("tablenames")) + { String value = (String) ScalingProperties.get("tablenames"); String[] tableNames = value.split(","); - for (String tableName : tableNames) { + for (String tableName : tableNames) + { //Check if there is a change requested for this hour String readProp = hour + "." + tableName + ".read"; String writeProp = hour + "." + tableName + ".write"; if (ScalingProperties.containsKey(readProp) - && ScalingProperties.containsKey(writeProp)) + && ScalingProperties.containsKey(writeProp)) { String readCapacity = ScalingProperties.getProperty(readProp); String writeCapacity = ScalingProperties.getProperty(writeProp); @@ -92,8 +100,7 @@ public Response scale(Object input, Context context) { //Check if there is a change requested for this hour String readProp = hour + "." + indexName + ".read"; String writeProp = hour + "." + indexName + ".write"; - if (ScalingProperties.containsKey(readProp) - && ScalingProperties.containsKey(writeProp)) + if (ScalingProperties.containsKey(readProp) && ScalingProperties.containsKey(writeProp)) { String readCapacity = ScalingProperties.getProperty(readProp); String writeCapacity = ScalingProperties.getProperty(writeProp); @@ -126,36 +133,35 @@ public Response scale(Object input, Context context) { * * @param message */ - private void log(String message) { - if (log != null) { + private void log(String message) + { + if (log != null) + { log.log(message); - } else { + } + else + { System.out.println(message); } } - private String scaleTable(String tableName, Long readCapacity, Long writeCapacity) { + private String scaleTable(String tableName, Long readCapacity, Long writeCapacity) + { Table table = dynamoDB.getTable(tableName); ProvisionedThroughput tp = new ProvisionedThroughput(); tp.setReadCapacityUnits(readCapacity); tp.setWriteCapacityUnits(writeCapacity); TableDescription d = table.describe(); - if (!Objects.equals(d.getProvisionedThroughput().getReadCapacityUnits(), readCapacity) || !Objects - .equals(d.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity)) { + if (!Objects.equals(d.getProvisionedThroughput().getReadCapacityUnits(), readCapacity) + || !Objects.equals(d.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity)) + { d = table.updateTable(tp); - return tableName - + "\nRequested read/write : " - + readCapacity - + "/" - + writeCapacity - + "\nCurrent read/write :" - + d.getProvisionedThroughput().getReadCapacityUnits() - + "/" - + d.getProvisionedThroughput().getWriteCapacityUnits() - + "\nStatus : " - + d.getTableStatus() - + "\n"; - } else { + return tableName + "\nRequested read/write : " + readCapacity + "/" + writeCapacity + + "\nCurrent read/write :" + d.getProvisionedThroughput().getReadCapacityUnits() + "/" + + d.getProvisionedThroughput().getWriteCapacityUnits() + "\nStatus : " + d.getTableStatus() + "\n"; + } + else + { return tableName + "\n Requested throughput equals current throughput\n"; } } @@ -167,14 +173,18 @@ private String scaleIndex(String tableName, String indexName, Long readCapacity, tp.setReadCapacityUnits(readCapacity); tp.setWriteCapacityUnits(writeCapacity); TableDescription d = table.describe(); - for (GlobalSecondaryIndexDescription indexDescription : d.getGlobalSecondaryIndexes()) { - if (Objects.equals(indexDescription.getIndexName(), indexName)) { + for (GlobalSecondaryIndexDescription indexDescription : d.getGlobalSecondaryIndexes()) + { + if (Objects.equals(indexDescription.getIndexName(), indexName)) + { if (!Objects.equals(indexDescription.getProvisionedThroughput().getReadCapacityUnits(), readCapacity) - || !Objects.equals(indexDescription.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity)) { + || !Objects.equals(indexDescription.getProvisionedThroughput().getWriteCapacityUnits(), writeCapacity)) + { d = table.getIndex(indexName).updateGSI(tp); return tableName + ":" + indexName + "\nRequested read/write : " + readCapacity + "/" + writeCapacity - + "\nCurrent read/write :" + d.getProvisionedThroughput().getReadCapacityUnits() + "/" + d.getProvisionedThroughput().getWriteCapacityUnits() - + "\nStatus : " + d.getTableStatus() + "\n"; + + "\nCurrent read/write :" + d.getProvisionedThroughput().getReadCapacityUnits() + "/" + + d.getProvisionedThroughput().getWriteCapacityUnits() + "\nStatus : " + d.getTableStatus() + + "\n"; } else { @@ -187,29 +197,30 @@ private String scaleIndex(String tableName, String indexName, Long readCapacity, private void setup() { - //Setup credentials - if (awsCreds == null) - { - awsCreds = new BasicAWSCredentials(access_key_id, secret_access_key); - } //Setup S3 client - if (s3Client == null) { + if (s3Client == null) + { s3Client = new AmazonS3Client(); } //Setup DynamoDB client - if (clnt == null) { + if (clnt == null) + { clnt = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain()); dynamoDB = new DynamoDB(clnt); clnt.setRegion(Region.getRegion(region)); } //Load properties from S3 - if (ScalingProperties == null) { - try { + if (ScalingProperties == null) + { + try + { ScalingProperties = new Properties(); S3Object object = s3Client.getObject(new GetObjectRequest(configBucketName, configKey)); S3ObjectInputStream stream = object.getObjectContent(); ScalingProperties.load(stream); - } catch (IOException ex) { + } + catch (IOException ex) + { log("Failed to read config file : " + configBucketName + "/" + configKey + "(" + ex.getMessage() + ")"); } } From 0045e3be622504d41e621e95f8a53c07f96645e8 Mon Sep 17 00:00:00 2001 From: John Lemp Date: Thu, 15 Jun 2017 15:40:03 -0400 Subject: [PATCH 4/5] fix bucketname --- serverless.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serverless.yml b/serverless.yml index 085bfa7..d5bc29d 100644 --- a/serverless.yml +++ b/serverless.yml @@ -5,7 +5,7 @@ frameworkVersion: ">=1.2.0 <2.0.0" custom: myStage: ${opt:stage, self:provider.stage} jarPath: target/uber-LambdaDynamoDBScaler-1.0-SNAPSHOT.jar - bucket: my-bucket-lambda-dynamodb-scaler-{self:custom.myStage} + bucket: my-bucket-lambda-dynamodb-scaler-${self:custom.myStage} dev: region: us-east-1 prod: @@ -57,4 +57,4 @@ resources: Properties: BucketName: ${self:custom.bucket} VersioningConfiguration: - Status: Enabled \ No newline at end of file + Status: Enabled From ce47fbf9b2d421153249412eb347f6c4fe376544 Mon Sep 17 00:00:00 2001 From: "shawn.kovalchick" Date: Fri, 16 Jun 2017 09:27:41 -0400 Subject: [PATCH 5/5] Fix property name string --- src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java index 8ba2c55..6ce45a4 100644 --- a/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java +++ b/src/main/java/be/quodlibet/lambdadynamodbscaler/Scaler.java @@ -98,8 +98,8 @@ public Response scale(Object input, Context context) String tableName = split[0]; String indexName = split[1]; //Check if there is a change requested for this hour - String readProp = hour + "." + indexName + ".read"; - String writeProp = hour + "." + indexName + ".write"; + String readProp = hour + "." + tableAndIndexName + ".read"; + String writeProp = hour + "." + tableAndIndexName + ".write"; if (ScalingProperties.containsKey(readProp) && ScalingProperties.containsKey(writeProp)) { String readCapacity = ScalingProperties.getProperty(readProp);