Hello, I made an example connecting by postgresql, using the console terminal aws it executes, however via terminal I am getting the following error:
$ curl.exe -I https://url-api.us-east-1.amazonaws.com/dev/hello-world
HTTP/2 403
content-type: application/json
content-length: 42
date: Mon, 12 Mar 2018 14:02:15 GMT
x-amzn-requestid: f7f98b53-25fd-11e8-beaa-e7723c28b74c
x-amzn-errortype: MissingAuthenticationTokenException
x-cache: Error from cloudfront
via: 1.1 e37f1f862adcf463c7e5850854dc15a7.cloudfront.net (CloudFront)
x-amz-cf-id: hspqX0Dpmu8qT54cdU38EK-fGW6UjiWh3hOBtXGbZ4rK9wZgooRXow==
Browser → {“message”: “Internal server error”}
I do not use any authentication
I’m just listing the data from a table in aws rds with postgres
service: serverless-hello-world
plugins:
- serverless-offline
provider:
name: aws
runtime: nodejs6.10functions:
helloWorld:
handler: handler.helloWorld
events:
- http:
path: hello-world
method: get
cors: true
My handler
‘use strict’;
const Sequelize = require(‘sequelize’);
const sequelize = new Sequelize(‘user’, ‘database’, ‘password’, {
host: ‘host’,
dialect: ‘postgres’
});const Task = sequelize.define(‘Task’, {
title: {
type: Sequelize.STRING(120),
allowNull: false
}
}, {
createdAt: ‘created_at’,
updatedAt: ‘update_at’,
tableName: ‘task’
});module.exports.helloWorld = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const model = Task;const options = {
attributes: [‘id’, ‘title’]
};model.findAndCountAll(options).then((data) => {
const response = {
statusCode: 200,
headers: {
‘Access-Control-Allow-Credentials’ : true
},
body: data
};callback(null, response);
}).catch((err) => {
const response = {
statusCode: 500,
headers: {
‘Access-Control-Allow-Credentials’ : true
},
body: err
};callback(null, response);
});
};