I'm migrating a small node/express app to lambda functions using serverless.
My app is really simple. No authentication. Just 1 endpoint, allowing GET and POST. The problem is GET works, but I'm getting HTTP error 403 when I send POST request sending a binary file (docx file)
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
/* GET home page. */
app.get('/', function (req, res, next) {
res.render('index', {title: 'Whatever'});
});
/* POST receive file */
app.post('/', function (req, res, next) {
// Simplified to the minimum
return res.json({'msg': 'ok'});
});
module.exports.handler = serverless(app);
My serverless.yml file looks like this
service: my_service
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: eu-west-3
functions:
app:
handler: app.handler
events:
- http: GET /
- http: 'ANY {proxy+}'
post:
handler: app.handler
events:
- http:
path: /
method: post
cors: true
After running sls deploy, an Amazon API Gateway is created and the function is deployed, but can't use POST to send binary files to my app.
This is probably a problem with API Gateway, but couldn't fix it.
EDIT
The first response is the correct one, with just a small change in the serverless.yml file. This is the right one:
service: my-service
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: eu-west-3
functions:
app:
handler: app.handler
events:
- http: GET /
- http: POST /
- http: 'ANY {proxy+}'