Skip to content

Instantly share code, notes, and snippets.

@brianfoody
Last active April 4, 2022 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianfoody/144e669012a4c3f09205e58ed39260cb to your computer and use it in GitHub Desktop.
Save brianfoody/144e669012a4c3f09205e58ed39260cb to your computer and use it in GitHub Desktop.
How to do a StepFunction cleanup post deploy
const taskWaitThreeHours = new sfn.Wait(this, "Wait 3 hours for tasks to have executed.", {
time: sfn.WaitTime.duration(cdk.Duration.hours(3))
});
const deprovisionLambda = new nodeLambda.NodejsFunction(this, "deprovisionFn", {
runtime: lambda.Runtime.NODEJS_14_X,
entry: "workflow/deprovision.ts",
handler: "main",
timeout: cdk.Duration.seconds(30),
logRetention: logs.RetentionDays.ONE_MONTH,
memorySize: 256,
});
allowManageProvisionTables(deprovisionLambda);
const deprovisionDefinition = sfn.Chain.start(taskWaitThreeHours).next(
new tasks.LambdaInvoke(
this,
"Ensure highly provisioned tables have been switched to PAY_PER_REQUEST",
{
lambdaFunction: deprovisionLambda
}
)
);
const deprovisionStateMachine = new sfn.StateMachine(this, "deprovisioner", {
definition: deprovisionDefinition,
stateMachineName: `${props.serviceName}-deprovision-wf`,
timeout: cdk.Duration.minutes(180),
tracingEnabled: true
});
new cr.AwsCustomResource(this, "InvokeDeprovisioner", {
onCreate: {
service: "StepFunctions",
action: "startExecution",
parameters: {
stateMachineArn: deprovisionStateMachine.stateMachineArn,
input: JSON.stringify("{}")
},
physicalResourceId: cr.PhysicalResourceId.of(
`${props.listenerName}-deprovision-wf-execute`
)
},
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment