Last active
November 3, 2021 16:09
-
-
Save sasknot/d3b53429c0995b4ff3e7701133a56b50 to your computer and use it in GitHub Desktop.
AWS Lambda Invoking (aws-sdk v2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWSLambda from 'aws-sdk/clients/lambda' | |
import { mode, modeIsDev } from '@/environment' | |
import type AWSSES from 'aws-sdk/clients/ses' | |
const lambda = new AWSLambda({ | |
endpoint: modeIsDev ? 'http://localhost:3002' : undefined | |
}) | |
const response = await lambda.invoke({ | |
FunctionName: `myApi-${mode}-email`, | |
InvocationType: 'RequestResponse', | |
Payload: JSON.stringify({ | |
pathParameters: {} | |
}) | |
}).promise() | |
if (!response || !response.Payload || typeof response.Payload !== 'string') { | |
throw new Error('Response is not valid') | |
} | |
const payload = JSON.parse(response.Payload) | |
if (!payload.body || typeof payload.body !== 'string') { | |
throw new Error('Response payload is not valid') | |
} | |
const responseBody: AWSSES.SendEmailResponse = JSON.parse(payload.body) | |
// responseBody output: | |
// { | |
// MessageId: 'unique-id' | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment