Skip to content

Instantly share code, notes, and snippets.

@danilop
Last active February 29, 2024 12:50
Show Gist options
  • Save danilop/75561c2660275fc328a68741f6d01066 to your computer and use it in GitHub Desktop.
Save danilop/75561c2660275fc328a68741f6d01066 to your computer and use it in GitHub Desktop.
Sample AWS SAM Template using Provisioned Concurrency with Application Auto Scaling
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Sample SAM Template using Application Auto Scaling + Provisioned Concurrency
Globals:
Function:
Timeout: 30
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.App::handleRequest
Runtime: java11
MemorySize: 1024
AutoPublishAlias: live
DeploymentPreference:
Type: AllAtOnce # Or Canary10Percent5Minutes, Linear10PercentEvery1Minute, ...
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: 1
Environment:
Variables:
ENVIRONMENT: test
Events:
HelloWorld:
Type: HttpApi # Using the new HTTP API here
MyScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 100
MinCapacity: 1
ResourceId: !Sub function:${MyFunction}:live # You need to specify an alis or version here
RoleARN: !Sub arn:aws:iam::${AWS::AccountId}:role/aws-service-role/lambda.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_LambdaConcurrency
ScalableDimension: lambda:function:ProvisionedConcurrency
ServiceNamespace: lambda
DependsOn: MyFunctionAliaslive # This is your function logical ID + "Alias" + what you use for AutoPublishAlias
MyTargetTrackingScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: utilization
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref MyScalableTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 0.70 # Any value between 0 and 1 can be used here
PredefinedMetricSpecification:
PredefinedMetricType: LambdaProvisionedConcurrencyUtilization
@xai1983kbu
Copy link

xai1983kbu commented Apr 7, 2021

line 50 should be:
TargetValue: 0.70 # Any value between 0.1 and 0.9 can be used here
see https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/

@PNTrong
Copy link

PNTrong commented May 14, 2021

Here is my solution:
"DependsOn": ["MyFunctionAliaslive"]
I use the list of strings instead of string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment