Skip to content

Commit

Permalink
fix: make sure lambda function is called with correct ARN
Browse files Browse the repository at this point in the history
  • Loading branch information
dzehnder committed Aug 5, 2024
1 parent d165ba0 commit 9e4663f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/backlinks/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default async function auditBrokenBacklinks(message, context) {
const { dataAccess, log, sqs } = context;
const {
AWS_REGION: region,
STATISTICS_SERVICE_LAMBDA: statisticsService,
SPACECAT_STATISTICS_LAMBDA_ARN: statisticsServiceArn,
AUDIT_RESULTS_QUEUE_URL: queueUrl,
} = context.env;

Expand Down Expand Up @@ -144,7 +144,7 @@ export default async function auditBrokenBacklinks(message, context) {
brokenBacklinks: auditResult.brokenBacklinks,
sitemapUrls,
region,
statisticsService,
statisticsServiceArn,
log,
});
} catch (e) {
Expand Down
12 changes: 6 additions & 6 deletions src/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,23 @@ export const extractKeywordsFromUrl = (url, log) => {
*/
export async function enhanceBacklinksWithFixes(config) {
const {
siteId, brokenBacklinks, sitemapUrls, region, statisticsService, log,
siteId, brokenBacklinks, sitemapUrls, region, statisticsServiceArn, log,
} = config;

const invoke = async (funcName, payload) => {
const invoke = async (funcArn, payload) => {
const client = new LambdaClient({ region });
const command = new InvokeCommand({
FunctionName: funcName,
FunctionName: funcArn,
Payload: JSON.stringify(payload),
LogType: LogType.Tail,
InvocationType: 'Event',
});

try {
await client.send(command);
log.info(`Lambda function ${funcName} invoked successfully.`);
log.info(`Lambda function ${funcArn} invoked successfully.`);
} catch (error) {
log.error(`Error invoking Lambda function ${funcName}:`, error);
log.error(`Error invoking Lambda function ${funcArn}:`, error);
}
};

Expand All @@ -258,7 +258,7 @@ export async function enhanceBacklinksWithFixes(config) {
},
};

invoke(statisticsService, payload); // No need to await this call
invoke(statisticsServiceArn, payload); // No need to await this call

return { status: 'Lambda function invoked' };
}
6 changes: 3 additions & 3 deletions test/support/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('enhanceBacklinksWithFixes', () => {
],
sitemapUrls: ['https://www.example.com/sitemap.xml'],
region: 'test-region',
statisticsService: 'testStatisticsService',
statisticsServiceArn: 'testStatisticsService',
log,
};

Expand Down Expand Up @@ -139,7 +139,7 @@ describe('enhanceBacklinksWithFixes', () => {
],
sitemapUrls: ['https://www.example.com/sitemap.xml'],
region: 'test-region',
statisticsService: 'testStatisticsService',
statisticsServiceArn: 'testStatisticsService',
log,
};

Expand All @@ -159,7 +159,7 @@ describe('enhanceBacklinksWithFixes', () => {
],
sitemapUrls: ['https://www.example.com/sitemap.xml'],
region: 'test-region',
statisticsService: 'testStatisticsService',
statisticsServiceArn: 'testStatisticsService',
log,
};

Expand Down

0 comments on commit 9e4663f

Please sign in to comment.