Skip to content
GitHubXDiscord

CustomResource

The CustomResource resource allows you to define custom actions and manage resources within AWS CloudFormation. For more details, refer to the AWS CloudFormation CustomResources documentation.

Create a basic custom resource with the required properties and a service timeout.

import AWS from "alchemy/aws/control";
const basicCustomResource = await AWS.CloudFormation.CustomResource("BasicCustomResource", {
ServiceToken: "arn:aws:lambda:us-east-1:123456789012:function:my-custom-resource-function",
ServiceTimeout: 300 // 5 minutes timeout
});

Configure a custom resource with the option to adopt existing resources.

const advancedCustomResource = await AWS.CloudFormation.CustomResource("AdvancedCustomResource", {
ServiceToken: "arn:aws:lambda:us-east-1:123456789012:function:my-custom-resource-function",
ServiceTimeout: 600, // 10 minutes timeout
adopt: true // Allow adoption of existing resources
});

Demonstrate how to adopt an existing custom resource without failing.

const resourceAdoptionExample = await AWS.CloudFormation.CustomResource("ResourceAdoptionExample", {
ServiceToken: "arn:aws:lambda:us-east-1:123456789012:function:my-custom-resource-function",
adopt: true // Adopt existing resource if it already exists
});

Show how to set a longer service timeout for complex operations.

const longTimeoutCustomResource = await AWS.CloudFormation.CustomResource("LongTimeoutCustomResource", {
ServiceToken: "arn:aws:lambda:us-east-1:123456789012:function:my-custom-resource-function",
ServiceTimeout: 1200 // 20 minutes timeout for long operations
});