A Guide to Amplify CLI - Part 2 - REST API

Introduction

In post, I'll walk you through the process of adding an API to your Amplify project. If you haven't initialized any Amplify project yet, head on to A Guide to Amplify CLI - Part 1

Before we start I assume you have already initialized an Amplify project on your system and have NPM installed.

In this post, I'll cover:

- amplify <category> add
- amplify <category> update
- amplify <category> remove
- amplify <category> push

Steps:

1. After your Amplify project has been initialized with `amplify init`, next type `amplify add api` on CMD.
2. Under mentioned services, select `REST`.

3. Next, type any name for your resource to be used as label. I am going with `products`

4. Next, give a path for your REST endpoint. For keeping it simple, let's go with `/product-items`

5. For `Lambda source`, it chooses `Create a new Lambda function` by itself. Next. type an AWS Lambda name for this. Example: ProductsLambda.

6. Choose `NodeJS` as the runtime.

7. Under `Choose the function template..`, select `Serverless ExpressJS function..`. The Lambda function template `Serverless ExpressJS function` implements route handlers for GET, POST, PUT and DELETE HTTP methods and paths for `/product-items` and `/product-items/*   `.

8. Type `N` to not configure advanced settings. We will touch this part later. Type 'Y' for "...edit the local lambda function now..". After this step, `src/app.js` opens in your VS Code window. 

9. Come back to your CMD and press enter to continue. Type 'Y' for "Restrict API access", next select `Authenticated and Guest user` for "Who should have access..", next under "What permissions..  grant to Authenticated users..", press spacebar on the entries if you want to select multple. Here, you should select all of them: create, read, update and delete. Use arrow keys to move up or down. After you have selected, press Enter.

10. Under "..permissions.. to Guest users", select only `read`.

11. Type `n` for "..add another path" and press Enter.

12. You get "Successfully added resource products locally" message on your CMD when configurations of your API is complete.

13. Let's deploy our new API to the cloud by typing the command: amplify push.

Now, what's next??

Comments

Popular

How To Create MySQL Table with SequelizeJS

How To Read CSV Files in Java as Maven Project

How To Create A Hibernate Project in Maven