API Gateway, Lambda, Postgres Crud
Install via npm:
npm install -g serverless
serverless deploy -v
serverless remove
Service Information
service: pins
stage: dev
region: us-east-1
stack: pins-dev
api keys:
None
endpoints:
GET - https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins
POST - https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins
GET - https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins/{id}
PUT - https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins/{id}
DELETE - https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins/{id}
functions:
list: pins-dev-list
create: pins-dev-create
get: pins-dev-get
update: pins-dev-update
delete: pins-dev-delete
Stack Outputs
DeleteLambdaFunctionQualifiedArn:
CreateLambdaFunctionQualifiedArn:
GetLambdaFunctionQualifiedArn:
UpdateLambdaFunctionQualifiedArn:
ListLambdaFunctionQualifiedArn:
ServiceEndpoint: https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev
ServerlessDeploymentBucketName:
curl -X GET https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins
curl -X POST https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins --data '{ "text": "First Todo" }'
curl -X GET https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins/123
curl -X PUT https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins/123 --data '{ "text": "First Todo" }'
curl -X DELETE https://0aaa0bbbbb.execute-api.us-east-1.amazonaws.com/dev/pins/123
const timestamp = new Date().getTime();
const data = JSON.parse(event.body);
if (typeof data.text !== 'string') {
console.error('Validation Failed');
callback(null, {
statusCode: 400,
headers: { 'Content-Type': 'text/plain' },
body: 'Couldn\'t create the todo item.',
});
return;
}
var response = {
"statusCode": 200,
"headers": {
"my_header": "my_value"
},
"body": JSON.stringify(res.rows[0]),
"isBase64Encoded": false
};
callback(null, response);