Task 2: Build a Serverless Function
|
Time to complete |
5 minutes |
|
Services used |
|
|
Requires |
A text editor. Here are a few free ones: |
|
Get help |
Overview
Now that you have a React web app, you will use AWS Amplify and AWS Lambda to configure a serverless function. This function is invoked after a signed-up user confirms their user account. AWS Lambda is a compute service that runs your code in response to events and automatically manages the compute resources, making it the fastest way to turn an idea into a modern, production, serverless applications.
Key concepts
Serverless function: Piece of code that will be executed by a compute service, on demand.
Implementation
-
Create files
On your local machine, navigate to the profilesapp/amplify/auth folder.
Create a new folder inside the amplify/auth folder and name it post-confirmation.
Create the files named resource.ts and handler.ts inside the folder.
-
Update the resources file
Update the amplify/auth/post-confirmation/resource.ts file with the following code to define the postConfirmation function. Then, save the file.
import { defineFunction } from '@aws-amplify/backend'; export const postConfirmation = defineFunction({ name: 'post-confirmation', });
-
Update the handler file
Update the amplify/auth/post-confirmation/handler.ts file with the following code to define the function’s handler. Then, save the file.
import type { PostConfirmationTriggerHandler } from "aws-lambda"; export const handler: PostConfirmationTriggerHandler = async (event) => { return event; };
Conclusion
You have defined a Lambda function using Amplify.