1

I'm using CDK to autoscale Lambda provisioned concurrency on a schedule. For example:

// Define the provisioned concurrency
const target = new asg.ScalableTarget(this, 'ScalableTarget', {
  serviceNamespace: asg.ServiceNamespace.LAMBDA,
  maxCapacity: 1,
  minCapacity: 0,
  resourceId: `function:${alias.lambda.functionName}:${alias.aliasName}`,
  scalableDimension: 'lambda:function:ProvisionedConcurrency'
});

target.node.addDependency(alias);

// Start the provisioned concurrency at 8am
target.scaleOnSchedule('ScaleUpInTheMorning', {
  schedule: asg.Schedule.cron({ hour: '08', minute: '00' }),
  minCapacity: 1,
  maxCapacity: 1
});

// Stop the provisioned concurrency at night
target.scaleOnSchedule('ScaleDownAtNight', {
  schedule: asg.Schedule.cron({ hour: '17', minute: '10' }),
  minCapacity: 0
  maxCapacity: 0
});

From what I have read and my own testing, the time in the cron definition is in UTC.

Is there a way to specify the timezone?

nixon
  • 1,952
  • 5
  • 21
  • 41
  • CDK maps to CloudFormation (CFN). In CFN you can set time zone. Thus you would have to find how to access low-level options for CFN to do that in my view. – Marcin Oct 20 '21 at 01:22
  • is there a particular reason you absolutely have to specify timezone? is converting to UTC an issue in some other way (other than readability?) – lynkfox Oct 20 '21 at 02:27
  • 1
    Yes there is a reason. For daylight savings time, my time zone changes from UTC+10 to UTC+11. – nixon Oct 20 '21 at 02:43

1 Answers1

2

You can achieve this with L1 constructs, since CloudFormation supports it: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-applicationautoscaling.CfnScalableTarget.html

I don't have any experience with TypeScript, so hopefully the following syntax is correct. In any case, you get the idea.

const target = new asg.CfnScalableTarget(this, 'ScalableTarget', {
  serviceNamespace: asg.ServiceNamespace.LAMBDA,
  maxCapacity: 1,
  minCapacity: 0,
  resourceId: `function:${alias.lambda.functionName}:${alias.aliasName}`,
  scalableDimension: 'lambda:function:ProvisionedConcurrency',
  scheduledActions: {
    schedule: asg.Schedule.cron(
      { hour: '08', minute: '00' }).expressionString,
    scheduledActionName: 'morning',
    timezone: 'Pacific/Tahiti'
  },
  scalableTargetAction: {
    minCapacity: 1,
    maxCapacity: 1
  }
});

gshpychka
  • 8,523
  • 1
  • 11
  • 31