diff --git a/packages/aws-cdk-lib/aws-codepipeline-actions/lib/s3/deploy-action.ts b/packages/aws-cdk-lib/aws-codepipeline-actions/lib/s3/deploy-action.ts index 91b265d4e3b01..f4ed6e5be53a0 100644 --- a/packages/aws-cdk-lib/aws-codepipeline-actions/lib/s3/deploy-action.ts +++ b/packages/aws-cdk-lib/aws-codepipeline-actions/lib/s3/deploy-action.ts @@ -25,16 +25,26 @@ export class CacheControl { public static noCache() { return new CacheControl('no-cache'); } /** The 'no-transform' cache control directive. */ public static noTransform() { return new CacheControl('no-transform'); } + /** The 'no-store' cache control directive. */ + public static noStore() { return new CacheControl('no-store'); } + /** The 'must-understand' cache control directive. */ + public static mustUnderstand() { return new CacheControl('must-understand'); } /** The 'public' cache control directive. */ public static setPublic() { return new CacheControl('public'); } /** The 'private' cache control directive. */ public static setPrivate() { return new CacheControl('private'); } + /** The 'immutable' cache control directive. */ + public static immutable() { return new CacheControl('immutable'); } /** The 'proxy-revalidate' cache control directive. */ public static proxyRevalidate() { return new CacheControl('proxy-revalidate'); } /** The 'max-age' cache control directive. */ public static maxAge(t: Duration) { return new CacheControl(`max-age=${t.toSeconds()}`); } /** The 's-max-age' cache control directive. */ public static sMaxAge(t: Duration) { return new CacheControl(`s-maxage=${t.toSeconds()}`); } + /** The 'stale-while-revalidate' cache control directive. */ + public static staleWhileRevalidate(t: Duration) { return new CacheControl(`stale-while-revalidate=${t.toSeconds()}`); } + /** The 'stale-if-error' cache control directive. */ + public static staleIfError(t: Duration) { return new CacheControl(`stale-if-error=${t.toSeconds()}`); } /** * Allows you to create an arbitrary cache control directive, * in case our support is missing a method for a particular directive. diff --git a/packages/aws-cdk-lib/aws-codepipeline-actions/test/s3/s3-deploy-action.test.ts b/packages/aws-cdk-lib/aws-codepipeline-actions/test/s3/s3-deploy-action.test.ts index a2d362a9602e0..243fa7e0128af 100644 --- a/packages/aws-cdk-lib/aws-codepipeline-actions/test/s3/s3-deploy-action.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline-actions/test/s3/s3-deploy-action.test.ts @@ -125,6 +125,23 @@ describe('S3 Deploy Action', () => { }); }); + test('cache-control directive has correct values', () => { + expect(cpactions.CacheControl.mustRevalidate().value).toEqual('must-revalidate'); + expect(cpactions.CacheControl.noCache().value).toEqual('no-cache'); + expect(cpactions.CacheControl.noTransform().value).toEqual('no-transform'); + expect(cpactions.CacheControl.noStore().value).toEqual('no-store'); + expect(cpactions.CacheControl.mustUnderstand().value).toEqual('must-understand'); + expect(cpactions.CacheControl.setPublic().value).toEqual('public'); + expect(cpactions.CacheControl.setPrivate().value).toEqual('private'); + expect(cpactions.CacheControl.immutable().value).toEqual('immutable'); + expect(cpactions.CacheControl.proxyRevalidate().value).toEqual('proxy-revalidate'); + expect(cpactions.CacheControl.maxAge(Duration.minutes(1)).value).toEqual('max-age=60'); + expect(cpactions.CacheControl.sMaxAge(Duration.minutes(1)).value).toEqual('s-maxage=60'); + expect(cpactions.CacheControl.staleWhileRevalidate(Duration.minutes(1)).value).toEqual('stale-while-revalidate=60'); + expect(cpactions.CacheControl.staleIfError(Duration.minutes(1)).value).toEqual('stale-if-error=60'); + expect(cpactions.CacheControl.fromString('custom').value).toEqual('custom'); + }); + test('allow customizing objectKey (deployment path on S3)', () => { const stack = new Stack(); minimalPipeline(stack, {