Skip to content

Instantly share code, notes, and snippets.

@tecmaverick
Forked from danilop/template.yaml
Created December 12, 2019 10:27
Show Gist options
  • Save tecmaverick/ce1be3e0cae2368c5bf310fb2a8fb1d9 to your computer and use it in GitHub Desktop.
Save tecmaverick/ce1be3e0cae2368c5bf310fb2a8fb1d9 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_Lambda
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment