Last active
April 4, 2022 03:32
-
-
Save brianfoody/144e669012a4c3f09205e58ed39260cb to your computer and use it in GitHub Desktop.
How to do a StepFunction cleanup post deploy
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
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