Skip to content

Instantly share code, notes, and snippets.

@congdang-agilityio
Created December 11, 2019 04:07
Show Gist options
  • Select an option

  • Save congdang-agilityio/a7b9aaa19745b5b038b212fbcf7cf3ea to your computer and use it in GitHub Desktop.

Select an option

Save congdang-agilityio/a7b9aaa19745b5b038b212fbcf7cf3ea to your computer and use it in GitHub Desktop.
CloudFormation template for setting up Lambda Provisioned Concurrency and AutoScaling by using Utilization metric
MyFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: hello
Code:
S3Bucket: lambda-repos
S3Key: hello.zip
Handler: lambda.handler
Environment:
Variables:
NODE_ENV: development
MemorySize: 256
TracingConfig:
Mode: Active
Role: !Ref LambdaExecutionRole
Runtime: nodejs10.x
Timeout: 600
LambdaVersion:
Type: AWS::Lambda::Version
Properties:
FunctionName: !Ref MyFunction
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: 1 # Start with 1
ScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: 100
MinCapacity: 1
ResourceId: !Join
- ":"
- - function
- !Ref MyFunction
- !GetAtt LambdaVersion.Version
RoleARN: !Ref LambdaScalingRole
ScalableDimension: lambda:function:ProvisionedConcurrency
ServiceNamespace: lambda
TargetTrackingScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: utilization
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref ScalableTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: 0.70 # Any value between 0 and 1 can be used here
PredefinedMetricSpecification:
PredefinedMetricType: LambdaProvisionedConcurrencyUtilization
@congdang-agilityio
Copy link
Author

congdang-agilityio commented Dec 11, 2019

Comment here if you wanted to ask something related to this gist. Give a star if you think it's helpful. Thanks!

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