This plugin can be used to update your CloudFront Distribution with API Gateway Origins and Cache Behaviors, so that the API gateway endpoints can be served through CloudFront.
npm install --save cloudfront-api-update
-
Require the module in your script.
const cau = require("cloudfront-api-update")
; -
Configure the required params. Note that
Origins
is an array, and there can be multiple Origins in the form of multiple objects.
const params = {
"DistributionId": "DISTRIBUTION_ID",
"Origins": [{
"DomainName": "api-id.execute-api.region.amazonaws.com",
"OriginPath": "",
"PathPattern": "/v1/api/*"
}
]
}
- Run the
updateDistribution
method to update your CloudFront Distribution.
cau.updateDistribution(params.DistributionId, params.Origins)
.then(results => {
console.log(results);
}).catch(error => {
console.error(error);
})