You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.*/constexpress=require('express')constbodyParser=require('body-parser')constawsServerlessExpressMiddleware=require('aws-serverless-express/middleware')constAWS=require('aws-sdk')// declare a new express appconstapp=express()constrouter=express.Router()router.use(bodyParser.json({limit: '10mb'}));router.use(awsServerlessExpressMiddleware.eventContext())// Enable CORS for all methodsrouter.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',asyncfunction(req,res){constsagemaker=newAWS.SageMakerRuntime({apiVersion: '2017-05-13',region:req.body.endpointRegion,});constresult=awaitsagemaker.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!
The text was updated successfully, but these errors were encountered:
The
lambda/app.js
timed out after 25 seconds and never appeared to enter theapp.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:
Fantastic tutorial by the way!
The text was updated successfully, but these errors were encountered: