aws-cdk-lib: Expose the ability to set a stack timeout to CloudFormation
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
# See [Latest Update from CDK team](https://github.com/aws/aws-cdk/issues/24792#issuecomment-1698810562)
### Describe the feature
[Issue 2125](https://github.com/aws/aws-cdk/issues/2125) requested a timeout option to the CDK in order to express the how long a stack should wait before it times out. It was stated that[ CloudFormation doesn't support this](https://github.com/aws/aws-cdk/issues/2125#issuecomment-479372418), but this statement is incorrect. The AWS CLI and SDKs have had the ability to express a stack timeout by setting the [--timeout-in-minutes](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html) on the stack being deployed. Frameworks such as Sceptre are able to leverage this feature and its [stack config takes a timeout argument](https://docs.sceptre-project.org/4.0.2/docs/stack_config.html#stack-timeout). This would be an incredibly useful addition to the CDK.
A comment in [issue 2125](https://github.com/aws/aws-cdk/issues/2125#issuecomment-552351375) states that this is solved by [#4572](https://github.com/aws/aws-cdk/pull/4572). It is curious why a solution involving custom resources has been deemed a solution to setting a stack timeout when the original issue cited deploying custom resources as the reason for expressing a timeout. In reality, setting a timeout has to happen in advance of deploying a stack.
### Use Case
There are several use cases where this feature is valuable. Quite often, the default time outs are simply too long. In cases where an ECS task has a code issue with a container image using a tag such as `latest` (I know, not the best practice, but some insist) and you get into a rollback loop pulling `latest` again. Another use case were things go south is when users mess up Route53 configuration for ACM. In this case, the timeout takes several hours. Being able to have CloudFormation to bail earlier would help a lot.
### Proposed Solution
The ability to set a stack timeout is not limited to the AWS CLI, but it is also possible to set this via the [AWS SDKs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cloudformation/interfaces/createstackcommandinput.html) as well. I would like to propose the ability to express a timeout both on a per-stack basis, as well as at the CDK App level. When a default timeout is specified on a CDK App:
```typescript
const app = new cdk.App({ defaultStackTimeout: Duration.minutes(20)} );
```
Optionally, a default stack time could be expressed by the CLI:
```bash
npx cdk -- deploy --all --stack-timeout-in-minutes 20
```
Each stack managed by the app gets its the same timeout. Both of the above options should yield the same behavior.
An individual stack may also express its own timeout, and override the `defaultStackTimeout` set by the CDK App.
```typescript
const myStack = new cdk.Stack(app, "MyStack", { stackTimeout: Duration.minutes(10)} );
```
In this case, `myStack` will use a shorter timeout than all the other stacks in the App.
### Other Information
_No response_
### Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.70.0
### Environment details (OS name and version, etc.)
masOS Ventura 13.2.1, RHEL 8
Contributor guide
Research direction
Trace the CDK App and Stack entry points, then follow the CLI deployment path to CloudFormation create-stack, using the issue’s AWS SDK and CLI timeout references as the behavioral contract. Confirm how per-stack and app-default values should interact, and verify that deployments pass the requested timeout to CloudFormation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100