Build a Basic Web Application

TUTORIAL

Task 2: Build a Serverless Function

In this task, you will use AWS Amplify and AWS Lambda to build a serverless function.

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.

 Minimum time to complete

5 minutes

 Services used

 Requires

Implementation

  • 1. On your local machine, navigate to the profilesapp/amplify/auth folder and create a new folder inside the amplify/auth folder, name it post-confirmation, and then create the files named resource.ts and handler.ts inside the folder.

    2. 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',
    });

    3. 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. 

Was this page helpful?

Link Serverless Function to Web App