How to Deploy a Severless Node.js API on AWS with the Amplify CLI and Amplify Functions

nader dabit
Instructornader dabit
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

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.

egghead
egghead
~ 18 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today