aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.56k stars 3.87k forks source link

Improved management of context caching #19797

Open gillisandrew opened 2 years ago

gillisandrew commented 2 years ago

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.
    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 <key or number> 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.

export interface ContextProviderPlugin {
    shouldRefresh(oldValue: any): Promise<boolean>;
    getValue(args: {
        [key: string]: any;
    }): Promise<any>;
}

Other Information

No response

Acknowledgements

CDK version used

2.19.0

Environment details (OS name and version, etc.)

Windows 11 (WSL2 Ubuntu 20.04)

rix0rrr commented 2 years ago

Interesting ideas, will keep them in mind, thanks.

In the mean time, the cdk context command was intended to be the primary method for interacting with those. I'm not opposed to changes that will make that command more powerful.

github-actions[bot] commented 1 year ago

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

RichiCoder1 commented 1 year ago

Bump.