Skip to content

Commit

Permalink
fix(applicationautoscaling): fix missing PredefinedMetric for Lambda …
Browse files Browse the repository at this point in the history
…provisioned concurrency
  • Loading branch information
pahud committed Feb 21, 2020
1 parent bb68f7c commit dfc6c9f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/@aws-cdk/aws-applicationautoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,43 @@ capacity.scaleOnSchedule('AllowDownscalingAtNight', {
schedule: autoscaling.Schedule.cron({ hour: '20', minute: '0' }),
minCapacity: 1
});
```

## Examples

### Lambda Provisioned Concurrency Auto Scaling

```ts
const handler = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
code: new lambda.InlineCode(`
import json, time
def handler(event, context):
time.sleep(1)
return {
'statusCode': 200,
'body': json.dumps('Hello CDK from Lambda!')
}`),
reservedConcurrentExecutions: 100,
});

const fnVer = handler.addVersion('CDKLambdaVersion', undefined, 'demo alias', 10);

new apigateway.LambdaRestApi(this, 'API', { handler: fnVer })

const target = new applicationautoscaling.ScalableTarget(this, 'ScalableTarget', {
serviceNamespace: applicationautoscaling.ServiceNamespace.LAMBDA,
maxCapacity: 100,
minCapacity: 10,
resourceId: `function:${handler.functionName}:${fnVer.version}`,
scalableDimension: 'lambda:function:ProvisionedConcurrency',
})

target.scaleToTrackMetric('PceTracking', {
targetValue: 1.0,
predefinedMetric: applicationautoscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
})
}
```

Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,5 @@ export enum PredefinedMetric {
SAGEMAKER_VARIANT_INVOCATIONS_PER_INSTANCE = 'SageMakerVariantInvocationsPerInstance',
ECS_SERVICE_AVERAGE_CPU_UTILIZATION = 'ECSServiceAverageCPUUtilization',
ECS_SERVICE_AVERAGE_MEMORY_UTILIZATION = 'ECSServiceAverageMemoryUtilization',
LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION = "LambdaProvisionedConcurrencyUtilization",
}

0 comments on commit dfc6c9f

Please sign in to comment.