Expanding functionality: Steps to integrating a new endpoint into your AWS Amplify Express Server

I have created a REST express server using Amplify.

Attempted to include two additional endpoints:

// incorporating serverless express
app.post('/myendpoint', function(req, res) {
  console.log('body: ', req.body)
  res.json(req.body)
});

// utilizing serverless express
app.get('/myendpoint', function(req, res) {
  res.json({success: 'get call to my endpoint succeed!', url: req.url});
});

Despite running amplify push, these new endpoints are not visible in the console and requests cannot be made to them via amplify.

The original configuration endpoints are functional. What is the correct procedure for adding more REST endpoints? It seems like I may have missed an additional configuration step.

Answer №1

Once the API and function have been deployed, to incorporate an extra path it is recommended to utilize the "amplify update api" command.

Answer №2

When using the "amplify update api" command, Kevin Le mentioned that you can easily add new root paths like "/items" or "/customers". However, I have encountered difficulties when trying to add nested paths such as "/customer/addAddress" after creating the initial API.

Here are some things I have attempted:

  1. I can include nested paths during the initial API setup, but not when updating it later on
  2. I tried modifying the cloud formation template to incorporate the nested paths in the API gateway, but any requests to these paths were intercepted by the root path's proxy
  3. Adding the nested paths directly in the express lambda function seemed like a workaround, but it goes against the purpose of utilizing API Gateway

In order to truly leverage the power of API Gateway and make the most out of Amplify's REST API capabilities, there is a need for enhancements. It would be beneficial to have the ability to separate functions for different HTTP methods like GET, POST, PUT, etc.

UPDATE: After further investigation, I discovered a solution to this issue. By removing the {proxy} endpoint associated with the "root" path in the cloud formation file for the API gateway, located at: "project root"/amplify/backend/api/"api name"/"api name"-cloudformation-template.json, the issue was resolved. Simply delete the path found under Resources->"api name"->Properties->Body->paths->"api name"/{proxy+}.

FURTHER INVESTIGATION: Although I have yet to test this, it is possible that the order of paths listed in the cloud formation file could impact how requests are processed. By reorganizing the paths so that the "root" proxy is placed last, it may eliminate the need to remove it altogether. Special thanks to Piotr for helping me correct my grammar!

Answer №3

To update your API in Amplify, simply run the command "amplify update api". From there, you can add a new endpoint and select a new or existing Lambda function to assign to that endpoint.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Refine keys dynamically according to the given input

I'm facing a challenge with an array wherein I need to filter out keys based on an input string. The only constant key is OLD_VAL, while the others are dynamic. Even though I attempted using a variable, it doesn't retrieve that specific key. let ...

"Scotchy McScotchface's to-do list application powered

How is the index.html (frontend Angular) being triggered? The tutorial mentioned that by including one of the following routes in route.js, the frontend gets called app.get('*', function(req, res) { res.sendfile('./public/index.html&ap ...

Steps for redirecting a user back to the previous page with passport-spotify

Currently, I am utilizing passport-spotify for authentication in my web application from this Github repository: https://github.com/jmperez/passport-spotify. However, I seem to be facing an issue with redirecting the user back to the previous page. I have ...

Tips for updating property values when calling a TypeScript function

Hello everyone, I am looking to convert a snippet of JavaScript code into TypeScript. JavaScript function newState(name){ var state ={ name : name, age : 0 } return state } function initStates() { this.JamesStat ...

Validation does not occur when the submit button has an ng-click event attached to it

This is the form I created: <form action="" ng-controller="forgotCtrl as forgot" name="forgotForm"> <div class="form-group row"> <label for="email" class="col-sm-2 form-control-label">Email address</label> ...

What was the reasoning behind Mozilla's decision to implement a conditional catch clause?

Discover the unique Conditional Catch Clauses from Mozilla Delve into this question out of pure curiosity - why would Mozilla venture beyond standard structures with this innovative feature? What specific challenges or issues is it designed to address? W ...

Sending data between modules in Node.js

I am currently working on a REST API project in node.js and have run into an issue when trying to pass data from one module to another. Since I am relatively new to node.js, I understand that there might be something crucial missing in my approach. My pro ...

Avoid reloading the page when the form is submitted using form.trigger('submit') command

My current code functions properly when the user clicks on the form's submit button: // load dashboards when filter form is submitted $('div.active form.filter-form').submit(function (e) { // get subm ...

Creating a customized image modal in ReactJS that incorporates a dynamic slideshow feature using the

I am attempting to incorporate an image lightbox into my React application: https://www.w3schools.com/howto/howto_js_lightbox.asp Here is the link to the CodeSandbox where I have tried implementing it: https://codesandbox.io/s/reactjs-practice-vbxwt ...

Encountered an issue while attempting to load the required module

I'm having trouble setting up Stripe for my app and getting errors when trying to implement the module. Typically, I would require the module at the top of the file in order to use it, but when I do this in the paymentCtrl file, it doesn't work a ...

Activating a function on a click or item selection in React using Office UI Fabric's

<div> <CommandBar areNamesVisible={false} areIconsVisible={true} items={[ { name:"James Towns", className:"noHoverEffect", }, { key:"Info", icon:"Contact", onItemClick={this.handlePanel} ...

Extracting and retrieving information from a complex data structure obtained through an API call

Struggling with this one. Can't seem to locate a similar situation after searching extensively... My goal is to determine the author of each collection associated with a user. I wrote a function to fetch data from an API for a specific user, in this ...

MongoDB Atlas Via Compass could not be loaded on Ubuntu due to an error

After recently downloading MongoDB Compass on Ubuntu, I decided to use the connection string from MongoDB Atlas to connect using MongoDB Compass. Upon opening MongoDB Compass, it automatically detected the connection string that I accepted. I then entered ...

Techniques for transferring PHP print_r arrays to Javascript

Array ( [0] => Array ( [sno] => 1 [name] => Sivamani [contact] => 750241378 [$city] => Madurai ) ) Array ( [1] => Array ( [sno] => 2 ...

"Using angularjs's $location.search method results in an empty object being

I am trying to retrieve my URL querystring in AngularJS using the $location service, similar to this example. My URL looks like this - http://someDomain.com/create/index.jsp?queryToken=123abc However, in my directive: vm.queryParam = $location.search(); ...

Vue.js / Nginx / Node.js - Error 413: Payload Too Big

My frontend is built using Vue.js and is hosted on an nginx server in production. Here's a snippet of my nginx.conf configuration: server { listen 80; server_name localhost; root /usr/share ...

"EPERM: unable to rename file due to permission restrictions" error occurs when using Express session with session-file-store library

Currently, I am developing a node application that operates on the express web server using express-session and session-file-store for managing sessions. Since incorporating these components into my project, my debug console has been inundated with errors ...

Guide on incorporating Bootstrap JS into HTML5 reusable web elements

RESOLVED: the solution is in a comment TL;DR: Issues triggering Bootstrap's JS, likely due to incorrect import of JS scripts I've been working on integrating Bootstrap with my custom reusable web components across all pages. Specifically, I&apo ...

Following the integration of DOTENV, the server functionality in the express application generated by express generator seems to have

Once I add DOTENV to the server setup in an Express application created using the express generator, the server stops working. Here is how I'm including DOTENV in my app.js file: require('dotenv').config({ path: 'variables.env' } ...

Comparing the cost of memory and performance between using classes and interfaces

As I delve into writing TypeScript for my Angular project, one burning question arises — should I use an Interface or a Class to create my domain objects? My quest is to uncover solid data regarding the actual implications of opting for the Class route. ...