aws / aws/aws-cdk

Improved management of context caching

Open
#19,797 3 comments 5 reactions 0 assignees View on GitHub
@aws-cdk/core @aws-cdk/custom-resources effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

Users need better tooling for managing context caching behaviors and for maintaining `cdk.context.json` cached values.

### Use Case

Users regularly open issues regarding stale values being returned by ContextProvider-enabled features (e.g. `Parameter.valueFromLookup`). As AWS itself recommends commiting `cdk.context.json` to source control to ensure reproducible builds, additional tooling should support maintaining it as well as control caching behaviors of lookups in general.

### Proposed Solution

1. Accept a validity duration as part of the lookup, after which the value will be refreshed by the context provider.
```typescript
export declare class StringParameter extends ParameterBase implements IStringParameter {
static valueFromLookup(scope: Construct, parameterName: string, validity?: Duration): string;
}
```
2. Accept filtering options for `cdk context --reset ` cli command. Allow wildcard key matching and environment-based filtering so unused values can be removed without impacting determinism of the synthesis.

If plugin-registered context-providers do eventually leave alpha, consider calling a staleness check with the cached values on context providers to support more complex cache-busting behaviors.
```typescript
export interface ContextProviderPlugin {
shouldRefresh(oldValue: any): Promise;
getValue(args: {
[key: string]: any;
}): Promise;
}
```

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.19.0

### Environment details (OS name and version, etc.)

Windows 11 (WSL2 Ubuntu 20.04)

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing StringParameter.valueFromLookup API and the cdk context --reset command, then inspect how cached values in cdk.context.json are maintained. Clarify whether the scope covers lookup validity, CLI filtering, or ContextProviderPlugin staleness checks; done requires an agreed scope with corresponding behavior and tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cli, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.