Invalidate cached content when an entry is published or unpublished to reflect the updated data on the client side and always return the updated content.
Here's a diagrammatic representation of a Contentstack-powered website.

First, let's set up an Automation Trigger for entry publish and unpublish events.
Steps to create automation for entry publish/unpublish events:

Prerequisites: Set up lambda function for invalidation using Cloudfront, which will be used in the HTTP connector.
Lambda code:
const AWS = require('aws-sdk');
exports.handler = async (event) => {
const { body, headers } = event;
const cloudfront_distribution_id = headers.cloudfront_distribution_id || '';
let idArray = cloudfront_distribution_id.split(',');
const responses = [];
for (const id of idArray) {
if (id !== '') {
const url = body && body.entry && body.entry.url;
const cloudfront = new AWS.CloudFront();
const params = {
DistributionId: id,
InvalidationBatch: {
CallerReference: Date.now().toString(),
Paths: {
Quantity: 1,
Items: [url],
},
},
};
try {
const data = await cloudfront.createInvalidation(params).promise();
responses.push({ message: `Cache cleared for Distribution ID: ${id}`, statusCode: 200 });
} catch (err) {
responses.push({ message: err.message, statusCode: 500 });
}
}
}
return {
statusCode: 200,
body: JSON.stringify(responses),
};
};

Activate Automation to run in a live environment.
Related guides: