In this video you will learn how to create and deploy a serverless Node.js API to AWS using the Amplify CLI, Amplify Functions, and the Amplify API category. Once the API is deployed, you will test it out from the command line and see the response in your terminal using CURL.
Nader Dabit: [0:00] To get started, create a new Amplify project by running amplify init. Choose the project's name, the environment's name, your default text editor, and the defaults for the rest of the options.
[0:16] When prompted for your AWS profile, choose the profile that you'd like to use. Once the project's been initialized, we'll add the API by running amplify add api. Here we'll choose REST as a type of API. For the API name, we'll call this greetingapi, as it will be returning a greeting. For the path we'll choose /hello.
[0:38] Since we don't have a Lambda function, we'll choose "Create a new Lambda function." We'll choose greetingfunction for the function name and NodeJS for the runtime. For the function template, we'll choose Hello World.
[1:00] When prompted to edit the local function now, choose Yes. The CLI should now open the function located at amplify/backend/function/greetingfunction in your text editor.
[1:11] In the function create a new variable called message, setting it to "Hello from Amplify API!" In the response, we'll set the message as the body and then, enable cores by setting Access-Control-Allow-Origin headers.
[1:36] To deploy the API and the function, we can run amplify push. We can now run amplify status at any time to see our REST endpoints. To test out the API, we can now curl the URL using the path of /hello.