Colm Cooney
Colm Cooney

Reputation: 145

Autoscale ProvisionedConcurrentExecutions AWS Lambda DependsOn value null

Im trying to add auto scaling to the Provisioned Concurrency configuration for our Lambdas on AWS. Im having trouble with the DependsOn: value for the Lambda target it doesnt seem recognize the resource im passing in and says its null. In the example from AWS its using AutoPublishAlias which isnt an option for me. https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/

Am I referencing incorrectly?

  **LambdaAlias:**
    Type: AWS::Lambda::Alias
    Properties:
      Description: Adds provisioned concurrency for lambda using alias on arn
      FunctionName: !Ref Lambda
      FunctionVersion: !GetAtt LambdaVersion.Version
      Name: live
      ProvisionedConcurrencyConfig:
        ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrentExecutions
           
   LambdaTarget:
     Type: AWS::ApplicationAutoScaling::ScalableTarget
     Properties:
       MaxCapacity: 100
       MinCapacity: 1
       ResourceId: !Sub function:${Lambda}:live # You need to specify an alis or version here
       RoleARN: !Ref IamRoleArn
       ScalableDimension: lambda:function:ProvisionedConcurrency
       ServiceNamespace: lambda
     **DependsOn: LambdaAlias** #  This is your function logical ID + "Alias" + what you use for AutoPublishAlias

   LambdaTrackingScalingPolicy:
     Type: AWS::ApplicationAutoScaling::ScalingPolicy
     Properties:
       PolicyName: utilization
       PolicyType: TargetTrackingScaling
       ScalingTargetId: !Ref LambdaTarget
       TargetTrackingScalingPolicyConfiguration:
         TargetValue: 0.70 #  Any value between 0.1 and 0.9 can be used here
         PredefinedMetricSpecification:
           PredefinedMetricType: LambdaProvisionedConcurrencyUtilization

Adding Resource Snippet

Resources:
  Lambda:
    Type: AWS::Lambda::Function
    Properties:
      !If
        - EnableVpcConfig
        - FunctionName: !Ref FunctionName
          Description: !Ref FunctionDescription
          Code:
            S3Bucket: !Ref CodeSourceBucket
            S3Key: !Sub 'api-packages/${CodeFile}'
          Handler: !Ref Handler
          Environment:
            Variables:
              APP_ID: !If [ UsesPublicKeyAPI, !Ref AppId, !Ref 

Solution

Answer was to reference the logical id of the AWS::Lambda::Alias resource I created which in this case was DependsOn: LambdaAlias

The doc was using AutoPublishAlias which didnt require the creation of a resource AWS::Lambda::Alias so config needed is slightly different

Upvotes: 2

Views: 701

Answers (2)

Damien
Damien

Reputation: 4121

Have you tried just using the name of the resource for the LambdaAlias I feel DependsOn: LambdaAlias should do the trick

You are using plain Cloudformation where the article you refer to is using AWS SAM.

Upvotes: 2

Parv Sharma
Parv Sharma

Reputation: 12705

since you are not using any AutoPublishAlias the format

{functionLogicalResourceName}Alias{aliasName}

should work for you..

In the sample you have provided. You have not provided the part which is deploying Lambda so if we assume your lambda logical id is MyLambda you should

DependsOn: MyLambdaAliaslive

Upvotes: 0

Related Questions