Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout on lambda/app.js #1

Open
trzimm opened this issue Oct 20, 2019 · 0 comments
Open

Timeout on lambda/app.js #1

trzimm opened this issue Oct 20, 2019 · 0 comments

Comments

@trzimm
Copy link

trzimm commented Oct 20, 2019

The lambda/app.js timed out after 25 seconds and never appeared to enter the app.post('/classify', async function(req, res) { function.

I was able to get it to work by the following the awslabs/aws-serverless-express example which I applied to your lambda function:

/*
Paste this into the app.js that Amplify opens for you when creating a new REST endpoint.
*/

const express = require('express')
const bodyParser = require('body-parser')
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware')
const AWS = require('aws-sdk')



// declare a new express app
const app = express()
const router = express.Router()
router.use(bodyParser.json({limit: '10mb'}));
router.use(awsServerlessExpressMiddleware.eventContext())

// Enable CORS for all methods
router.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token");
  next();
})

router.post('/classify', async function(req, res) {
  const sagemaker = new AWS.SageMakerRuntime({
    apiVersion: '2017-05-13',
    region:req.body.endpointRegion,
  });

  const result = await sagemaker.invokeEndpoint({
    Body: Buffer.from(req.body.base64Image, 'base64'),
    EndpointName: req.body.endpointName,
    ContentType: 'application/x-image',
    Accept: 'application/json',
  }).promise();

  res.json({predictions: JSON.parse(result.Body.toString())})
})


// The aws-serverless-express library creates a server and listens on a Unix
// Domain Socket for you, so you can remove the usual call to app.listen.
// app.listen(3000)
app.use('/', router)

// Export your express server so you can import it in the lambda function.
module.exports = app

Fantastic tutorial by the way!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant