Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Created December 31, 2021 13:54
Show Gist options
  • Select an option

  • Save leegilmorecode/e2898511fd15fda5938910e4515d097a to your computer and use it in GitHub Desktop.

Select an option

Save leegilmorecode/e2898511fd15fda5938910e4515d097a to your computer and use it in GitHub Desktop.
CDK API Gateway setting for path based caching
// integrate the lambda to the method - GET /blogs
blogs.addMethod(
"GET",
new apigw.LambdaIntegration(listBlogsHandler, {
proxy: true,
allowTestInvoke: true,
})
);
// integrate the lambda to the method - GET /blog/{id}
const blog: apigw.Resource = blogs.addResource("{id}");
blog.addMethod(
"GET",
new apigw.LambdaIntegration(getBlogHandler, {
proxy: true,
allowTestInvoke: true,
// ensure that our caching is done on the id path parameter
cacheKeyParameters: ["method.request.path.id"],
cacheNamespace: "blogId",
requestParameters: {
"integration.request.path.id": "method.request.path.id",
},
}),
{
requestParameters: {
"method.request.path.id": true,
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment