NodeJS: Create AWS CloudFront Invalidation

9/29/2021 5:35:54 PM

let AWS = require("aws-sdk");
let cloudfront = new AWS.CloudFront({ region: "us-east-1" });

async function cloudfront__invalidation(distribution_id)
{
    console.log("cloudfront__invalidation: " + distribution_id);

    var params = {
        DistributionId: distribution_id,
        InvalidationBatch: {
            CallerReference: new Date().getTime().toString(), /* required */
            Paths: {
                Quantity: 1,
                Items: ['/*']
            }
        }
    };
    console.log(params);

    return await cloudfront.createInvalidation(params).promise();
}