Skip to content

Commit

Permalink
DO-1610: remove looping as the queue message should have only one mes…
Browse files Browse the repository at this point in the history
…sage
  • Loading branch information
Chris Park committed Jan 31, 2024
1 parent 2d4c69f commit 982e755
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, SQSEvent, SQSRecord } from "aws-lambda";
import { Context, SQSEvent } from "aws-lambda";
import axios from "axios";

const userAgent = "prerender / Googlebot recaching request";
Expand All @@ -9,13 +9,17 @@ const userAgent = "prerender / Googlebot recaching request";
* @param context - The AWS Lambda context object.
*/
export const handler = async (event: SQSEvent, _context: Context) => {
event.Records.forEach(async (record: SQSRecord) => {
const url = record.body;
console.log(`Fetching ${url} for recaching`);
await axios.get(url, {
headers: {
"User-Agent": userAgent,
},
});
// Only one item in the message is assumed.
const url = event.Records[0].body;
console.log(`Fetching ${url} for recaching`);
const res = await axios.get(url, {
headers: {
"User-Agent": userAgent,
},
});
console.log(
`Requested ${url} recaching, got ${JSON.stringify(
res.status
)}, response headers: ${JSON.stringify(res.headers)}`
);
};

0 comments on commit 982e755

Please sign in to comment.