0% found this document useful (0 votes)
34 views

Deploy A REST API Using Serverless, Express and Node - Js

This document provides steps to deploy a REST API using Serverless, Express, and Node.js. It will: 1) Deploy a simple API endpoint to return "Hello World!" as a proof of concept. 2) Add a DynamoDB table and two API endpoints - one to create a user object and another to retrieve a user object. This demonstrates integrating a database. 3) Configure the Serverless service for local development and granular metrics/monitoring of API endpoints.

Uploaded by

zaninn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Deploy A REST API Using Serverless, Express and Node - Js

This document provides steps to deploy a REST API using Serverless, Express, and Node.js. It will: 1) Deploy a simple API endpoint to return "Hello World!" as a proof of concept. 2) Add a DynamoDB table and two API endpoints - one to create a user object and another to retrieve a user object. This demonstrates integrating a database. 3) Configure the Serverless service for local development and granular metrics/monitoring of API endpoints.

Uploaded by

zaninn
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

We will:

sign-up free
Deploy a simple API endpoint
Add a DynamoDB table and two endpoints to create and retrieve a User object
Search blogs Set up path-specific routing for more granular metrics and monitoring
Configure your environment for local development for a faster development
experience.

guides & tutorials


If you already have an Express application that you want to convert to Serverless, skip to
the Converting an existing Express application section below.
Deploy a REST API using Serverless,
Express and Node.js Getting Started
written by Alex DeBrie
To get started, you'll need the Serverless Framework installed. You'll also need your
environment configured with AWS credentials.

To make the most of this tutorial, sign up for Serverless


Framework’s dashboard account for free:
Creating and deploying a single endpoint
https://app.serverless.com
Let's start with something easy—deploying a single endpoint. First, create a new directory
with a package.json file:
We're seeing more and more people using Serverless to deploy web applications. The
benefits are huge—lightning-fast deployments, automatic scaling, and pay-per-
execution pricing. $ mkdir my-express-application && cd my-express-application
$ npm init -f

But moving to serverless has a learning curve as well. You need to learn the intricacies of
the platform you're using, including low-level details like format of the request input and
the required shape of the response output. This can get in the way and slow your Then, let's install a few dependencies. We'll install the express framework, as well as the
development process. serverless-http :

Today, I come with good news: your existing web framework tooling will work seamlessly
with Serverless. In this post, I'll show you how to use the popular Node web framework $ npm install --save express serverless-http

Express.js to deploy a Serverless REST API. This means you can use your existing code +
💥
the vast Express.js ecosystem while still ge ing all the benefits of Serverless !

The serverless-http package is a handy piece of middleware that handles the


Below is a step-by-step walkthrough of creating a new Serverless service using Express.js. interface between your Node.js application and the specifics of API Gateway. Huge
subscribe subscribe
thanks to Doug Moscrop for developing it.
# serverless.yml
With our libraries installed, let's create an index.js file that has our application code:
service: my-express-application

provider:
// index.js
name: aws
runtime: nodejs6.10
const serverless = require('serverless-http');
stage: dev
const express = require('express')
region: us-east-1
const app = express()

functions:
app.get('/', function (req, res) {
app:
res.send('Hello World!')
handler: index.handler
})
events:
- http: ANY /
module.exports.handler = serverless(app);
- http: 'ANY {proxy+}'

This is a very simple application that returns "Hello World!" when a request comes in
This is a pre y basic configuration. We've created one function, app , which uses the
on the root path / .
exported handler from our index.js file. Finally, it's configured with some HTTP triggers.

It's straight out of the Express documentation with two small additions. First, we
We've used a very broad path matching so that all requests on this domain are routed to
imported the serverless-http package at the top. Second, we exported a handler
this function. All of the HTTP routing logic will be done inside the Express application.
function which is our application wrapped in the serverless package.

Now, deploy your function:


To get this application deployed, let's create a serverless.yml in our working directory:

subscribe subscribe
backing store.
$ sls deploy
... snip ...
For this simple example, let's say we're storing Users in a database. We want to store
Service Information
service: my-express-application them by userId , which is a unique identifier for a particular user.
stage: dev
region: us-east-1 First, we'll need to configure our serverless.yml to provision the table. This involves
stack: my-express-application-dev
three parts:
api keys:
None
endpoints: . Provisioning the table in the resources section;
ANY - https://bl4r0gjjv5.execute-api.us-east-1.amazonaws.com/dev . Adding the proper IAM permissions; and
ANY - https://bl4r0gjjv5.execute-api.us-east-1.amazonaws.com/dev/{proxy+ . Passing the table name as an environment variable so our functions can use it.
functions:
app: my-express-application-dev-app
Change your serverless.yml to look as follows:

A er a minute, the console will show your endpoints in the Service Information # serverless.yml
section. Navigate to that route in your browser:
service: my-express-application

custom:
tableName: 'users-table-${self:provider.stage}'

provider:
name: aws
runtime: nodejs6.10
stage: dev
region: us-east-1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Your application is live! - dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Adding a DynamoDB table with REST-like Resource:

endpoints - { "Fn::GetAtt": ["UsersDynamoDBTable", "Arn" ] }


environment:
USERS_TABLE: ${self:custom.tableName}
It's fun to get a simple endpoint live, but it's not very valuable. O en, your application
will need to persist some sort of state to be useful. Let's add a DynamoDB table as our
subscribe functions: subscribe
b ki t app:
app: Then update your index.js as follows:
handler: index.handler
events:
- http: ANY /
// index.js
- http: 'ANY {proxy+}'

const serverless = require('serverless-http');


resources:
const bodyParser = require('body-parser');
Resources:
const express = require('express')
UsersDynamoDBTable:
const app = express()
Type: 'AWS::DynamoDB::Table'
const AWS = require('aws-sdk');
Properties:
AttributeDefinitions:
-
const USERS_TABLE = process.env.USERS_TABLE;
AttributeName: userId
const dynamoDb = new AWS.DynamoDB.DocumentClient();
AttributeType: S
KeySchema:
app.use(bodyParser.json({ strict: false }));
-
AttributeName: userId
app.get('/', function (req, res) {
KeyType: HASH
res.send('Hello World!')
ProvisionedThroughput:
})
ReadCapacityUnits: 1
WriteCapacityUnits: 1
// Get User endpoint
TableName: ${self:custom.tableName}
app.get('/users/:userId', function (req, res) {
const params = {
TableName: USERS_TABLE,
Key: {
We provisioned the table in the resources section using CloudFormation syntax. We userId: req.params.userId,
also added IAM permissions for our functions under the iamRoleStatements portion of },
the provider block. Finally, we passed the table name as the environment variable }
USERS_TABLE in the environment portion of the provider block.
dynamoDb.get(params, (error, result) => {
if (error) {
Now, let's update our application to use the table. We'll implement two endpoints: POST
console.log(error);
/user to create a new user, and GET /user/{userId} to get information on a particular res.status(400).json({ error: 'Could not get user' });
user. }
if (result.Item) {
const {userId, name} = result.Item;
First, install the aws-sdk and body-parser , which is used for parsing the body of HTTP
res.json({ userId, name });
requests:
} else {
res.status(404).json({ error: "User not found" });
}
$ npm install --save aws-sdk body-parser });
})

subscribe // Create User endpoint subscribe


Then update your index js as follows: app post('/users' function (req res) {
app.post( /users , function (req, res) {
const { userId, name } = req.body;
if (typeof userId !== 'string') { export BASE_DOMAIN=https://bl4r0gjjv5.execute-api.us-east-1.amazonaws.com/
res.status(400).json({ error: '"userId" must be a string' });
} else if (typeof name !== 'string') {
res.status(400).json({ error: '"name" must be a string' });
} Then, let's create a user:

const params = {
TableName: USERS_TABLE,
$ curl -H "Content-Type: application/json" -X POST ${BASE_DOMAIN}/users -d
Item: {
{"userId":"alexdebrie1","name":"Alex DeBrie"}
userId: userId,
name: name,
},
};
Nice! We've created a new user! Now, let's retrieve the user with the GET /users/:userId`
dynamoDb.put(params, (error) => { endpoint:
if (error) {
console.log(error);
res.status(400).json({ error: 'Could not create user' });
$ curl -H "Content-Type: application/json" -X GET ${BASE_DOMAIN}/users/alex
}
{"userId":"alexdebrie1","name":"Alex DeBrie"}
res.json({ userId, name });
});
})

module.exports.handler = serverless(app); Perfect!

This isn't a full-fledged REST API, and you'll want to add things like error handling,
authentication, and additional business logic. This does give a framework in which you
In addition to base "Hello World" endpoint, we now have two new endpoints:
can work to set up those things.

GET /users/:userId for ge ing a User


POST /users for creating a new User
Path-specific routing
Let's deploy the service and test it out!
Let's take another look at our function configuration in serverless.yml :

functions:
$ sls deploy
app:
handler: index.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
We'll use curl for these examples. Set the BASE_DOMAIN variable to your unique domain
and base path so it's easier to reuse:
subscribe We're forwarding all traffic on the domainsubscribe
to our application and le ing Express handle
h i f h i l i Th i b fi hi I d ' h ll i
your application, and all requests to POST /users/ will be handled by the createUser
the entirety of the routing logic. There is a benefit to this—I don't have to manually string
instance. For any other requests, they'll be handled by the main app instance of your
up all my routes and functions. I can also limit the impact of cold-starts on lightly-used
function.
routes.

Again, none of this is required, and it's a bit of an overweight solution since each specific
However, we also lose some of the benefits of the serverless architecture. I can isolate my
endpoint will include the full application code for your other endpoints. However, it's a
bits of logic into separate functions and get a decent look at my application from
standard metrics. If each route is handled by a different Lambda function, then I can see: good balance between speed of development by using the tools you're used to along
with the per-endpoint granularity that serverless application pa erns provide.
How many times each route is invoked
How many errors I have for each route
How long each route takes (and how much money I could save if I made that route Local development configuration with
faster)
Serverless offline plugin
Luckily, you can still get these things if you want them! You can configure your
When developing an application, it's nice to rapidly iterate by developing and testing
serverless.yml so that different routes are routed to different instances of your
locally rather than doing a full deploy between changes. In this section, I'll show you how
function.
to configure your environment for local development.

Each function instance will have the same code, but they'll be segmented for metrics
First, let's use the serverless-offline plugin. This plugin helps to emulate the API
purposes:
Gateway environment for local development.

# serverless.yml Install the serverless-offline plugin:

functions:
app: $ npm install --save-dev serverless-offline
handler: index.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
Then add the plugin to your serverless.yml :
getUser:
handler: index.handler
events:
- http: 'GET /users/{proxy+}' # serverless.yml

createUser:
handler: index.handler plugins:

events: - serverless-offline

- http: 'POST /users'

Then, start the serverless-offline server:


Now, all requests to GET /users/:userId will be handled by the getUser instance of
subscribe subscribe
your application and all requests to POST /users/ will be handled by the createUser
/ p

Luckily, there's a plugin for doing local development with a local DynamoDB emulator!
We'll use the serverless-dynamodb-local plugin for this.

First, let's install the plugin:

$ npm install --save-dev serverless-dynamodb-local


$ sls offline start
Serverless: Starting Offline: dev/us-east-1.
Then, let's add the plugin to our serverless.yml . Note that it must come before the
Serverless: Routes for app: serverless-offline plugin. We'll also add some config in the custom block so that it
Serverless: ANY / locally creates our tables defined in the resources block:
Serverless: ANY /{proxy*}

Serverless: Routes for getUser:


Serverless: GET /users/{proxy*} # serverless.yml

Serverless: Routes for createUser: plugins:

Serverless: POST /users - serverless-dynamodb-local


- serverless-offline #serverless-offline needs to be last in the list

Serverless: Offline listening on http://localhost:3000


custom:
tableName: 'users-table-${self:provider.stage}'
dynamodb:
start:
Then navigate to your root page on localhost:3000 in your browser:
migrate: true

Then, run a command to install DynamoDB local:

$ sls dynamodb install

Finally, we need to make some small changes to our application code. When instantiating
our DynamoDB client, we'll add in some special configuration if we're in a local, offline
It works! If you make a change in your index.js file, it will be updated the next time you environment. The serverless-offline plugin sets an environment variable of
hit your endpoint. This rapidly improves development time. IS_OFFLINE to true , so we'll use that to handle our config. Change the beginning of
index.js to the following:

While this works easily for a stateless endpoint like "Hello World!", it's a li le trickier for
subscribe subscribe
our /users endpoints that interact with a database.
running locally or uses the default options if running in Lambda.

Let's see it if works. Start up your offline server again:

$ sls offline start


Dynamodb Local Started, Visit: http://localhost:8000/shell
Serverless: DynamoDB - created table users-table-dev
Serverless: Starting Offline: dev/us-east-1.

Serverless: Routes for app:


Serverless: ANY /
Serverless: ANY /{proxy*}

Serverless: Routes for getUser:

// index.js Serverless: GET /users/{proxy*}

const serverless = require('serverless-http'); Serverless: Routes for createUser:

const bodyParser = require('body-parser'); Serverless: POST /users

const express = require('express')


const app = express() Serverless: Offline listening on http://localhost:3000

const AWS = require('aws-sdk');

const USERS_TABLE = process.env.USERS_TABLE;


Let's run our curl command from earlier to hit our local endpoint and create a user:
const IS_OFFLINE = process.env.IS_OFFLINE;
let dynamoDb;
if (IS_OFFLINE === 'true') {
dynamoDb = new AWS.DynamoDB.DocumentClient({
region: 'localhost',
endpoint: 'http://localhost:8000'
}) $ curl -H "Content-Type: application/json" -X POST http://localhost:3000/us
console.log(dynamoDb); {"userId":"alexdebrie1","name":"Alex DeBrie"}
} else {
dynamoDb = new AWS.DynamoDB.DocumentClient();
};
And then retrieve the user:
app.use(bodyParser.json({ strict: false }));

... rest of application code ...


$ curl -H "Content-Type: application/json" -X GET http://localhost:3000/users
{"userId":"alexdebrie1","name":"Alex DeBrie"}

Now, our DocumentClient constructor is configured


subscribe to use DynamoDB local if we're subscribe
i l ll th d f lt ti if i i L bd
region: us-east-1
It works just like it did on Lambda!

functions:
This local setup can really speed up your workflow while still allowing you to emulate a app:
close approximation of the Lambda environment. handler: app.handler
events:
- http: ANY /

Converting an existing Express application


- http: 'ANY {proxy+}'

If you already have an existing Express application, it's very easy to convert to a
Serverless-friendly application. Do the following steps:
That's it! Run sls deploy and your app will deploy!

. Install the serverless-http package -- npm install --save serverless-http


Note that if you use other resources (databases, credentials, etc.), you'll need to make
. Add the serverless-http configuration to your Express application. You’ll need to
sure those make it into your application, likely via Environment Variables.
import the serverless-h p library at the top of your file: const serverless =
require('serverless-http'); then export your wrapped application:
module.exports.handler = serverless(app);. For reference, an example
application might look like this: Additional Resources
# app.js
Here are a few other resources you might find useful while building Express applications
with Serverless:
const serverless = require('serverless-http'); <-- Add this.
const express = require('express')
Adding a custom domain name to your API
const app = express()
3 Steps to Faster Serverless Development
Monitoring with Metrics and Alarms
... All your Express code ... Function introspection with logging

module.exports.handler = serverless(app); <-- Add this.


``` Architectural Diagram
. Set up your serverless.yml with a single function that captures all traffic:

# serverless.yml

service: express-app

provider:
name: aws
runtime: nodejs6.10
stage: dev subscribe subscribe
region: us east 1
express framework, is that not a good way to create APIs ?
2 ) Can i create local serverless environment and mongodb
environment in every context ?
3) Where it is preferred to create REST APIs using the way given in
article and the lambda function API way ?

Thank You.
44 △ ▽ • Reply • Share ›

Alex D > Anubhav Gupta • 3 years ago


Thanks, Anubhav!

About Alex DeBrie For 1 & 3, it's completely fine to make Node APIs without the
Express framework. I've written this example as an easier
Alex DeBrie is a data engineer at Serverless. on-ramp for those who are already familiar with Express or
who want to move existing Express applications over. If
you're happy with using the Lambda functions directly, go for
it!

For question 2, are you asking if you can do local


development with Mongo instead of DynamoDB? If so, the
answer is yes -- you'll just need to pass in the proper
ALSO ON SERVERLESS-INC
connection string to your local Mongo database rather than
your production version.
△ ▽ • Reply • Share ›
Managing Stages and Container Image re:Invent 20
Stephen Huh > Alex D • 3 years ago
Environments Support for AWS … API Gatewa
Hey @Alex D could you possibly go into some of the
a year ago • 1 comment 2 months ago • 6 comments a year ago • 5 c downsides of using this without the Express
Being able to manage Container Image Support for AWS just anno framework? I'm conflicted on whether to handle it
multiple different stages of AWS Lambda has now been support for HT myself, but I have noticed that the serverless.yml files
deployment within … added. Read up on why … AWS API Gate would look pretty different in this guide if express
wasnt sitting as a middleware.
2△ ▽ • Reply • Share ›
41 Comments serverless-inc 🔒 Privacy Policy
Nandakishore Nekkanti > Stephen Huh
• 2 years ago
 Leonardo Zanin
one of the downsides w/o express.
 Recommend 4 t Tweet f Share Sort by Best https://serverless.com/blog...
△ ▽ • Reply • Share ›
⚠ serverless-inc requires you to verify your email address before ×
posting. Send verification email to Shawn Nolan Jr. • 3 years ago
This was awesome, thx for this, much appreciated and mad respect.
Keep up the good work!
14 △ ▽ • Reply • Share ›
Join the discussion…
AngryMatt • 3 years ago
Anubhav Gupta • 3 years ago Hi, Thanks for the article. When I tried to use the code, however, I
Nice Article ! I have some questions in my mind after reading this : get no endpoints like the ones you formed on AWS. I always get
1 ) I have been using lambda function assubscribe
an API without using endpoints: none. Second, no matter what, subscribe
I am unable to get the
f k i th t t d t t API ? e press code to ork (inde js) E er thing I ha e tried res lts in a
g g
express code to work (index.js). Everything I have tried results in a
server error unless I use the stock handler.js functions. That works The Same
fine. △ ▽ • Reply • Share ›
The -http: ANY / does not do anything for me. Is this syntax correct?
I see no mention of it in the docs anywhere. da592 • 2 years ago • edited

4△ ▽ • Reply • Share › question, does it mean that each lambda call we are building
complete api instance that can accept all of the endpoints ?
memelorde • 8 hours ago • edited or something behind the scene split all the endpoints into
if you're getting an error telling you to upgrade node js runtime, in independent functions before deploy ?
serverless.yml change it to this
thanks
provider: △ ▽ • Reply • Share ›
runtime: 12.x
and everything else ANSHUL NEGI • 2 years ago

△ ▽ • Reply • Share › Nice article


I have a question i.e how to enable cors in this?
PatrickDarj • 3 months ago △ ▽ • Reply • Share ›
Hey, thanks for your article!
Do you have an idea about how we can perform unit testing on this victor hazbun • 2 years ago
kind of project ? Where is the repo?
△ ▽ • Reply • Share › △ ▽ • Reply • Share ›

conkiu soft • 5 months ago Lautaro Paskevicius • 2 years ago


Very interesting framework. We will try with serverless in our next I belive this snippet in index.js is causing an error that makes the
project . Seems easily for set up to work with AWS . service go down. Basically, when you try to create a user and it fails,
△ ▽ • Reply • Share › you throw the error AND the you try to respond with the userId as if
it had been successful. This causes a Can't set headers after they
Adam Berk • a year ago are sent error.
Thanks for the article. I am unable to get the server to handle the
incoming request though this node application works perfectly on
dynamoDb.put(params, (error) => {
my local windows machine. I put console logs in the index.js and
if (error) {
app.js and they are showing up but the app.get seems not to be
console.log(error);
invoked. Lambda returns a document with a 404. I suspect
res.status(400).json({ error: 'Could not create user' });
something is missing in the configuration but have no clue from the
}
output what is wrong. Not sure if the serverless deploy is at fault.
res.json({ userId, name });

S });

△ ▽ • Reply • Share ›
<html lang="en"><head>
<meta charset="utf-8"> pirahana • 2 years ago
<title>Error</title> Hi, the article is great. I needed one help, if possible can use write
</head> an example where we deploy a these APIs with a custom lambda
<body> authorizer which is in some other domain. I am trying the same.
This is my serverless.yml file,
Cannot POST /invUpdateApp-dev-app

provider:
</body>
name: aws
</html>
runtime: nodejs10.x
△ ▽ • Reply • Share › stage: dev
subscribe region: us-east-1 subscribe
Carlos Villegas > Adam Berk • 7 months ago
function without having to redeploy all of them? I tried sls deploy
functions: function -f myFunction. It updated the code in lambda but I cannot
app: see the change when I invoke it.
handler: app.server △ ▽ • Reply • Share ›
events:
- http: Narendra Kothule • 3 years ago
path: / Nice Article!!
method: ANY Do you have any reference to deploy serverless app using Express
cors tr e on Azure Function app service?
see more Thank you.
△ ▽ • Reply • Share › △ ▽ • Reply • Share ›

thehme • 2 years ago James Morcom • 3 years ago


Great article. Being familiar with express, this was a great way to try I'm getting a 404 response with body "Cannot GET /dev/" from the
serverless. endpoint.
△ ▽ • Reply • Share › It seems to work OK locally when I use `serverless invoke local --
function app`
Eric Kirsner • 2 years ago △ ▽ • Reply • Share ›
Thanks for this excellent guide! For me, the DynamoDB local install
command sls dynamodb install produced no output and when I Muhammad Muhajir > James Morcom • 3 years ago
tried to start serverless-offline I received this message: same
2△ ▽ • Reply • Share ›
Unable to start DynamoDB Local process!
For debugging logs, run again after setting the "SLS_DEBUG=*" James Morcom > Muhammad Muhajir • 3 years ago
environment variable.
I went back and got this one to work OK.
I resolved it by using sls dynamodb install --localPath ./bin and https://serverless.com/lear...
it worked great! Thanks to this comment. Maybe it's the CORS stuff?

△ ▽ • Reply • Share › △ ▽ • Reply • Share ›

Carlos Villegas > James Morcom


Rudy Akram • 2 years ago
• 7 months ago
Very well explained, how to custom domain in the API gateway also
What was the solution for that ?
add authorization based on cognito authorizer from API gateway?
△ ▽ • Reply • Share ›
△ ▽ • Reply • Share ›
Tyrone • 3 years ago
Jeff Cubinski • 2 years ago
Nice article indeed! Everything works as expected; when testing my
Love the blog post. I got the Hello World working. Question why
API in postman everything works.
doesn't the function that is deployed show up in AWS in Lambda?
Shouldn't it be? It runs find just not in the Lambda dashboard. However when using the API in an angular web app which is hosted
△ ▽ • Reply • Share › in an S3 bucket; I keep getting CORS issues. Is there anything I
must do there that I might have missed? Already enabled CORS in
thegreenpizza > Jeff Cubinski • 2 years ago the API gateway..
If I had to guess I would say check your region on AWS. If △ ▽ • Reply • Share ›
you can hit it at the AWS url it definitely is deployed on some
lambda. Daniel Ortiz Vega • 3 years ago

△ ▽ • Reply • Share › in params When I execute. shows: Missing required key 'Bucket'
△ ▽ • Reply • Share ›
Diego R FG • 3 years ago
Really really really helpful!!! Is there a way to deploy a specific
subscribe Sridhar Duggireddy • 3 years ago
subscribe
function without having to redeploy all of them? I tried sls deploy Hi Thank you for the article I noticed that there are some
Hi, Thank you for the article. I noticed that there are some
Coming from koa/expressJS background, this is a good article to
differences in syntax in serverless.yml with the new serverless
get started with Serverless Framework.
framework. Also, I noticed that serverless.yml is missing
DynamoDBIamPolicy segment. I had to add it to authorize my app
correctly. This is what I added.

DynamoDBIamPolicy:
Type: AWS::IAM::Policy
DependsOn: UsersDynamoDBTable New to serverless?
Properties:
PolicyName: lambda-dynamodb To get started, pop open your terminal & run:
PolicyDocument: npm install serverless -g
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:GetItem documentation
- dynamodb:PutItem
Resource: arn:aws:dynamodb:*:*:table/${self:custom.tableName}
Roles: examples
- Ref: IamRoleLambdaExecution
△ ▽ • Reply • Share › plugins

Michael Lashinsky • 3 years ago


Getting a "malformed Lambda proxy response" on the get method
for the user. Any idea what it doesn't like about the response
coming back? The post seems fine from curl, postman, and AWS
Console testing. The get doesn't want to play nice.
△ ▽ • Reply • Share ›

Scott Jones • 3 years ago


Do you have an example of a REST endpoint deployed on AWS
and what it would take to deploy the same to Azure. I am interested
in how easy that might be. If we have direct reference to dynamoDB
how will that be handled
Join our monthly newsle er
△ ▽ • Reply • Share ›

Narendra Kothule > Scott Jones • 3 years ago e-mail address subscribe
Hi Scott, I am also looking for serverless application using
express to deploy on Azure Functions app. did you used
azure function app service? do you have any reference?

Thanks
[email protected] - Copyright © 2021 Serverless, Inc. All rights reserved.
△ ▽ • Reply • Share ›

JF • 3 years ago
The demo did not create any endpoints...
△ ▽ • Reply • Share ›

edmandiesamonte • 3 years ago subscribe subscribe

You might also like