I'm trying to develop a data pipeline using AWS lambda and I needed to know if it auto-scales immediately or does it require a warm-up time?
Lambda has this concept of Provisioned concurrency. From the docs:
Provisioned concurrency initializes a requested number of execution environments so that they are prepared to respond immediately to your function's invocations. Note that configuring provisioned concurrency incurs charges to your AWS account.
You can set a value for how many execution environments be prepared for parallel invocations. This will guarantee that your lambda wont require a warm-up time as long as you stay inside that value and you wont have more parallel executions.
Otherwise, it wont be guaranteed that your function will be warmed-up. If you have nothing set for provisioned concurrency, you most likely will have cold-starts.
Does anywhere officially or unofficially document what the true maximums are for all AWS quotas?
I am new to AWS, and am trying to figure out the maximum values for certain quotas.
For example, the default value for S3 Access Points supports a maximum of 1000 per account.
but in the AWS quota console it says it is Adjustable, and the docs suggest I can request a quota increase.
You can create a maximum of 1,000 access points per AWS account per Region. If you need more than 1,000 access points for a single account in a single Region, you can request a service quota increase. For more information about service quotas and requesting an increase, see AWS Service Quotas in the AWS General Reference.
I'd like to know what the true maximums are across the board for IAM and S3 resources, to ease design of features I'm working on, without having to do a request to increase resources I may not actually use, if appropriate resource limits can't be requested.
After discussing with AWS support, some quota changes aren't reflected in this console at this time (e.g dynamoDb quota changes)
Haven't tried it, but possibly using aws-limit-checker may show the real limits
I'm hosting a static website in Amazon S3 with CloudFront. Is there a way to set a limit for how many reads (for example per month) will be allowed for my Amazon S3 bucket in order to make sure I don't go above my allocated budget?
If you are concerned about going over a budget, I would recommend Creating a Billing Alarm to Monitor Your Estimated AWS Charges.
AWS is designed for large-scale organizations that care more about providing a reliable service to customers than staying within a particular budget. For example, if their allocated budget was fully consumed, they would not want to stop providing services to their customers. They might, however, want to tweak their infrastructure to reduce costs in future, such as changing the Price Class for a CloudFront Distribution or using AWS WAF to prevent bots from consuming too much traffic.
Your static website will be rather low-cost. The biggest factor will likely be Data Transfer rather than charges for Requests. Changing the Price Class should assist with this. However, the only true way to stop accumulating Data Transfer charges is to stop serving content.
You could activate CloudTrail data read events for the bucket, create a CloudWatch Event Rule to trigger an AWS Lambda Function that increments the number of reads per object in an Amazon DynamoDB table and restrict access to the objects once a certain number of reads has been reached.
What you're asking for is a very typical question in AWS. Unfortunately with near infinite scale, comes near infinite spend.
While you can put a WAF, that is actually meant for security rather than scale restrictions. From a cost-perspective, I'd be more worried about the bandwidth charges than I would be able S3 requests cost.
Plus once you put things like Cloudfront or Lambda, it gets hard to limit all this down.
The best way to limit, is to put Billing Alerts on your account -- and you can tier them, so you get a $10, $20, $100 alerts, up until the point you're uncomfortable with. And then either manually disable the website -- or setup a lambda function to disable it for you.
AWS Lambda seems nice for running stress tests.
I understand that is it should be able scale up to 1000 instances, and you are charged by 0.1s rather than per hour, which is handy for short stress tests. On the other hand, automatically scaling up gives you even less control over costs than EC2. For development having explicit budget would be nice. I understand that Amazon doesn't allow for explicit budgets since they can bring down websites in their moment of fame. However, for development having explicit budget would be nice.
Is there a workaround, or best practices for managing cost of AWS Lambda services during development? (For example, reducing the maximum time per request)
Yes, every AWS Lambda function has a setting for defining maximum duration. The default is a few seconds, but this can be expanded to 5 minutes.
AWS also has the ability to define Budgets and Forecasts so that you can set a budget per service, per AZ, per region, etc. You can then receive notifications at intervals such as 50%, 80% and 100% of budget.
You can also create Billing Alarms to be notified when expenditure passes a threshold.
AWS Lambda comes with a monthly free usage tier that includes 3 million seconds of time (at 128MB of memory).
It is unlikely that you will experience high bills with AWS Lambda it is being used for its correct purpose, which is running many small functions (rather than for long-running purposes, for which EC2 is better).
Amazon DynamoDB doesn’t provide inbuild capabilities to auto tune throughput based on Dynamic Load.
It provide API to increase or Decrease throughput. Customers are being charges hourly basis for provisioned read & write throughput.
What are the different ways to alter throughput of dynamodb and achieve cost saving benefits ?
The answer from Chris is an accurate answer. Just to add a few points from prior experience using DynamoDB …
The situation with DynamoDB is different from EC2. The elastic compute service has an API supported directly as a web service by Amazon to allow you to program how to scale up or down according some logic such as how much demand exists. You program this by defining a monitoring threshold and automatically triggering creation or deletion of instances in a group.
Data servers do not work in the same way with triggers to adjust their capacity. But the capacity of DynamoDB is very flexible and may be controlled as Chris has pointed out. The API to provide this is good enough to make one off changes. Or equivalent manual changes from the console.
The different language bindings to program create and update actions with DynamoDB is here …
http://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html
The important operation to modify capacity is here …
http://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-table.html
So this gives you the ability to make an increase or decrease in the ReadCapacityUnits or WriteCapacityUnits of ProvisionedThroughput.
Which is fine for a predicted or one-off change. But that is not the same thing as a flexibility tool to allow you to trigger the change automatically.
Programmatically, what you are most likely to want to do is to adjust capacity in response to change in utilization in the preceding time interval. In particular you may need to scale up rapidly in response to a surge in demand by defining an appropriate time slot and a lower and upper threshold to trigger.
A more complete solution to achieve this is described here …
https://aws.amazon.com/blogs/aws/auto-scale-dynamodb-with-dynamic-dynamodb/
The solution is maintained by Sebastian Dahlgren and may be found with all instructions at …
https://github.com/sebdah/dynamic-dynamodb
I see that the current release is 1.18.5 which is more recent than when I last used it.
Judging from earlier releases it is simple to configure by means of a dynamodb.conf properties style file …
Having provided credentials and region, the most crucial settings are
check-interval — to test throughput in seconds
min-provisioned-reads, max-provisioned-reads; reads-upper-threshold, reads-lower-threshold; increase-reads-with, decrease-reads-with — These are all percentages
min-provisioned-writes, max-provisioned-writes; writes-upper-threshold, writes-lower-threshold; increase-writes-with, decrease-writes-with — These are all percentages
Is this information up to date?
Well if you look at http://aws.amazon.com/new/ you will see just one additional recent change affecting DynamoDB which affects the documents stored. The entry for Dynamic DynamoDB is the last published entry dealing with scaling actions. So this is the best maintained DynamoDB automatic scaling capability at this time.
Amazon just added autoscaling for dynamodb, see the details here
I just discovered this project that will autoscale up and down your Dynamodb and looks better than Dynamic Dynamo, because it uses Lambda functions rather than EC2 instances:
https://github.com/channl/dynamodb-lambda-autoscale
5 minute setup process
Serverless design
Flexible code over configuration style
Autoscale table and global secondary indexes
Autoscale multiple tables
Autoscale by fixed settings
Autoscale by provisioned capacity utilisation
Autoscale by throttled event metrics
Optimised for large spikes in usage and hotkey issues by incorporating throttled event metrics
Optimised performance using concurrent queries
RateLimitedDecrement as imposed by AWS
Statistics via 'measured'
AWS credential configuration via 'dotenv'
Optimised lambda package via 'webpack'
ES7 code
100% Flow static type checking coverage
You can manage throughput programmatically through the updateTable API or manually through the console.
There's also tools like Dynamic DynamoDB, though you could roll your own version as well: you'd use the updateTable API and have some background process running to detect those circumstances and call updateTable as necessary.
Some things to watch out for when changing the scale of DynamoDB:
You get billed for allocated throughput, whether you're actually using it or not.
Wen you scale up, Dynamo may allocate new partitions for you - but it won't remove them when it scales down. This can result in unexpected hot hash key problem where you have a lot of partitions but very low throughput on each of them.
Jeff Bar recently wrote a blog in AWS official blog: "Auto Scale DynamoDB With Dynamic DynamoDB":
https://aws.amazon.com/blogs/aws/auto-scale-dynamodb-with-dynamic-dynamodb/
He introduced Dynamic DynamoDB, an open source tool built by independent developer to handle this automatically with CloudFormation template.
I think other answers have done a great job but I have a different approach to autoscale DynamoDB in an event driven fashion by leveraging CloudWatch alarms and DynamoDB's UpdateTable operation to change provisioned capacity. The following approach not only helps to reduce costs, but to scale up capacity for unexpected loads.
Summary:
Configure CloudWatch alarms on DynamoDB metrics to alert you based on thresholds and push the alerts to an SQS queue via SNS topic. A daemon process which polls SQS queue can process those alerts and change table provisioned capacity using DynamoDB's UpdateTable operation and update CloudWatch alarm thresholds.
Detailed version:
Please be advised that this approach would require 1. Understanding of AWS services like CloudWatch, SNS, SQS 2. Good amount of time for implementing in your favorite programming language 3. Maintaining a daemon to process SQS messages and change the provisioned capacity.
One time setup:
Create CloudWatch alarms on ConsumedWriteCapacityUnits and ConsumedReadCapacityUnits metrics of your DynamoDB table. You can use this documentation.
Configure the CloudWatch alarms to alert a SNS topic. Create an AWS SQS queue and subscribe the queue to receive alerts from SNS topic.
Write a daemon in any programming language to poll SQS queue and process all alerts. AWS has SDKs in multiple languages so choosing any of those languages would avoid writing lot of code to communicate with AWS services.
Daemon algorithm:
For every SQS message it receives, calculate the new provisioned capacity to be used and issue an UpdateTable operation with the new value.
Update the CloudWatch alarm with the new thresholds, if required.
You can use above approach to either scale up or down. For example, maintain CloudWatch alarm threshold at 80% of ProvisionedWriteCapacityUnits and every time the usage crosses 80%, increase the capacity and set alarm threshold to 80% of new value. Similarly you can scale down when the consumption falls below x%.
Though this is the crux, there would be lot of points to be considered in a production quality solution.
Understand about DynamoDB partitions and hot key problems.
Be aware of all DynamoDB limits.
Constraints on no.of scale downs per UTC day.
Batching the multiple UpdateTable operations.
Finally, Neptune.io provides a packaged SaaS solution to autoscale DynamoDB by using this architecture. See http://blog.neptune.io/one-click-autoscaling-of-dynamodb/ and http://blog.neptune.io/dos-and-donts-of-dynamodb-autoscaling/ for some reading on that.
P.S: I work for Neptune. And, I can help you if you need more details of implementation.
I added new features to Rockeee Dynamic DynamoDB Lambda. You can see this project:
https://github.com/touchvie/dynamic-dynamodb-lambda
Global Secondary Index support
Enable/Disable read/write autoscaling in config json file
Throttle Events in CloudWatch support
Enable/Disable throttle-read/throttle-write checking in config json file
Added test to lambda
I hope that it can help you.
AWS added native auto scaling support for DynamoDB in June 2017. See the announcement here.
You can configure this using code (Java SDK example), but if you have just a few tables, you can use the Management Console. Click in your table configuration and select the Capacity tab. The following image shows what are your options:
Guidelines for DynamoDB Auto Scaling Script :
Customers are being charged on hourly basis for provisioned read & write throughput. Below is Amazon Dynamo DB Pricing for EU (Ireland Region).
• Write Throughput: $0.00735 per hour for every 10 units of Write Capacity
• Read Throughput: $0.00735 per hour for every 50 units of Read Capacity
Amazon Dynamo DB doesn’t provide in-build capabilities to auto tune throughput based on Dynamic Load. It provides API to increase or Decrease throughput with some restrictions like throughput can be decreased twice in a day and increased any time in a day.
What will be the monthly bill of a Production Table for fixed read capacity 2,000 read/second and 2,000 write/second for 24 hours?
Calculation: $0.00735 X 24hrs X 200 X 30days {write cost for month} + $0.00735X 24hrs X 40 X 30 days {read cost for month} = 1058.4+ 211.68 = Fixed 1270 $/month.
Guidelines for writing utility {amazon supported programming languages} which adjust throughput of table and reduces monthly bills.
(A) Initial Value: Basically, here you have to watch and decide read & write throughput for table as an initialization value after analyzing average usage considering 15 days or 1 month load and add X% extra for read and Y% extra for write on the top to withstand unexpected load.
Initial read/write throughput = calculate read throughput based on average usage +X {read} % or Y {write} %
X & Y can be anything between 10% and 30% based on observation.
(B) Peak Load Shaping: Alert on tables can be set as when load reaches to 50% to 60 % of provisioned throughput, necessary action can be taken like calling throughput increment API to increase throughput anything between 30 % to 50% of provision throughput.*
(C) Manual Shaping: For known heavy load like batch load/festival season, throughput should be set manually to 200% - 300% extra of normal daily operations until load is complete*
* Once business working hours or load is over. Throughput should reduce down to initial value.
Note: Reader can calculate monthly saving considering 1,000 read/write for 16 hrs. + 2,000 read/write for 8 hours, provided utility in place.
Now that AWS has announced scheduled execution of lambda services, these seem a great fit to do time-based auto scaling. I wrote up an example of how to use this on medium. Example code is on github.
AWS added native auto scaling support for DynamoDB in June 2017. The following code (source) provides an example of how to configure auto scaling using the Java SDK:
package com.amazonaws.codesamples.autoscaling;
import com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScalingClient;
import com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest;
import com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult;
import com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesRequest;
import com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesResult;
import com.amazonaws.services.applicationautoscaling.model.MetricType;
import com.amazonaws.services.applicationautoscaling.model.PolicyType;
import com.amazonaws.services.applicationautoscaling.model.PredefinedMetricSpecification;
import com.amazonaws.services.applicationautoscaling.model.PutScalingPolicyRequest;
import com.amazonaws.services.applicationautoscaling.model.RegisterScalableTargetRequest;
import com.amazonaws.services.applicationautoscaling.model.ScalableDimension;
import com.amazonaws.services.applicationautoscaling.model.ServiceNamespace;
import com.amazonaws.services.applicationautoscaling.model.TargetTrackingScalingPolicyConfiguration;
public class EnableDynamoDBAutoscaling {
static AWSApplicationAutoScalingClient aaClient = new AWSApplicationAutoScalingClient();
public static void main(String args[]) {
ServiceNamespace ns = ServiceNamespace.Dynamodb;
ScalableDimension tableWCUs = ScalableDimension.DynamodbTableWriteCapacityUnits;
String resourceID = "table/TestTable";
// Define the scalable target
RegisterScalableTargetRequest rstRequest = new RegisterScalableTargetRequest()
.withServiceNamespace(ns)
.withResourceId(resourceID)
.withScalableDimension(tableWCUs)
.withMinCapacity(5)
.withMaxCapacity(10)
.withRoleARN("SERVICE_ROLE_ARN_GOES_HERE");
try {
aaClient.registerScalableTarget(rstRequest);
} catch (Exception e) {
System.err.println("Unable to register scalable target: ");
System.err.println(e.getMessage());
}
// Verify that the target was created
DescribeScalableTargetsRequest dscRequest = new DescribeScalableTargetsRequest()
.withServiceNamespace(ns)
.withScalableDimension(tableWCUs)
.withResourceIds(resourceID);
try {
DescribeScalableTargetsResult dsaResult = aaClient.describeScalableTargets(dscRequest);
System.out.println("DescribeScalableTargets result: ");
System.out.println(dsaResult);
System.out.println();
} catch (Exception e) {
System.err.println("Unable to describe scalable target: ");
System.err.println(e.getMessage());
}
System.out.println();
// Configure a scaling policy
TargetTrackingScalingPolicyConfiguration targetTrackingScalingPolicyConfiguration =
new TargetTrackingScalingPolicyConfiguration()
.withPredefinedMetricSpecification(
new PredefinedMetricSpecification()
.withPredefinedMetricType(MetricType. DynamoDBWriteCapacityUtilization))
.withTargetValue(50.0)
.withScaleInCooldown(60)
.withScaleOutCooldown(60);
// Create the scaling policy, based on your configuration
PutScalingPolicyRequest pspRequest = new PutScalingPolicyRequest()
.withServiceNamespace(ns)
.withScalableDimension(tableWCUs)
.withResourceId(resourceID)
.withPolicyName("MyScalingPolicy")
.withPolicyType(PolicyType.TargetTrackingScaling)
.withTargetTrackingScalingPolicyConfiguration(targetTrackingScalingPolicyConfiguration);
try {
aaClient.putScalingPolicy(pspRequest);
} catch (Exception e) {
System.err.println("Unable to put scaling policy: ");
System.err.println(e.getMessage());
}
// Verify that the scaling policy was created
DescribeScalingPoliciesRequest dspRequest = new DescribeScalingPoliciesRequest()
.withServiceNamespace(ns)
.withScalableDimension(tableWCUs)
.withResourceId(resourceID);
try {
DescribeScalingPoliciesResult dspResult = aaClient.describeScalingPolicies(dspRequest);
System.out.println("DescribeScalingPolicies result: ");
System.out.println(dspResult);
} catch (Exception e) {
e.printStackTrace();
System.err.println("Unable to describe scaling policy: ");
System.err.println(e.getMessage());
}
}
}
This code requires that you supply an ARN for a valid Application Auto Scaling service role. Replace SERVICE_ROLE_ARN_GOES_HERE with the actual ARN.