future-yak-43516
01/22/2020, 8:57 PMhandsome-truck-95168
01/22/2020, 10:22 PMaws
CLI has a specific command for this, so I just use that. My pulumi job outputs the distribution created/updated and then I invalidate afterwards:
aws cloudfront create-invalidation --distribution-id $(pulumi -s xxx stack output distribution) --paths /
distribution
is the ID of the distribution, exported from the stack xxx
).future-yak-43516
01/23/2020, 5:17 AMminiature-musician-31262
01/23/2020, 9:02 PMprocess.on("beforeExit", async (code) => {
// Only proceed for updates that are also successful.
if (pulumi.runtime.isDryRun() || code !== 0) {
return;
}
// Use .apply() to get at the generated CloudFront distrubution ID.
cdn.id.apply(async (id) => {
const cloudfront = new aws.sdk.CloudFront();
const result = await cloudfront.createInvalidation({
DistributionId: id,
InvalidationBatch: {
CallerReference: "someref",
Paths: {
Quantity: 1,
Items: [
"/someitem.html",
],
},
},
})
.promise();
console.log(result.Invalidation);
// And then don't forget to actually exit.
process.exit(0);
});
});
future-yak-43516
01/25/2020, 8:16 PM