Last active
February 29, 2024 12:50
-
-
Save danilop/75561c2660275fc328a68741f6d01066 to your computer and use it in GitHub Desktop.
Sample AWS SAM Template using Provisioned Concurrency with Application Auto Scaling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
I also would like to know if a solution was found..
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/
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
Hi @daorte
Could you find a solution for line 41? the only workaround we could came up with was adding scaling through a new cfn which being called after sam goes in successfully... would appreciate if anyone has a cleaner approach to share
Thanks