Pietro Di Bello
I like to code, test-drive, design, build and run software. I enjoy talking about agile methods, lean software development and more broadly about every principle, practice or process that improve the way we work day by day.
@pierodibello
No ops, just code
@dedaniel_xp
CLOUD COMPUTING PLATFORM
AMAZON WEB SERVICES
https://cloud.google.com/functions/
https://azure.microsoft.com/en-us/services/functions/
{
"name": "photosAll",
"customName": false,
"customRole": false,
"handler": "photos/photosAll/handler.handler",
"runtime": "nodejs4.3",
"timeout": 6,
"memorySize": 1024,
"custom": {},
"endpoints": [
{
"path": "photos",
"method": "GET",
"type": "AWS",
"authorizationType": "none",
"authorizerFunction": false,
"apiKeyRequired": false,
"requestParameters": {},
"requestTemplates": "$${apiRequestTemplate}",
"responses": "$${apiResponses}"
}
],
"events": [],
"vpc": {
"securityGroupIds": ["${securityGroupId}"],
"subnetIds": ["${subnetId}"]
},
"environment": "$${environment}"
}
'use strict';
var PhotoRepository = require('../../lib/photo/PhotoRepository');
var PhotographerRepository = require('../../lib/photographer/PhotographerRepository');
var PhotoDetail = require('../../lib/photo/PhotoDetail');
var LambdaRequest = require('../../lib/LambdaRequest');
var Auth = require('../../lib/Auth');
module.exports.handler = function(event, context) {
var request = new LambdaRequest(event, context);
var loggedPhotographer;
Auth.getUser(request.getParams())
.then(function(user) {
if (!user) {
return null;
}
return PhotographerRepository.findByUserId(user.getId());
})
.then(function(photographer) {
loggedPhotographer = photographer;
return PhotoRepository.findAllApprovedBy(request.getParams());
})
.then(function(collection) {
var jsonCollection = collection.toJSON();
jsonCollection.items.map((photo) => PhotoDetail(photo, loggedPhotographer));
return jsonCollection;
})
.then(request.succeed)
.catch(request.fail)
.finally(request.tearDown);
};
@pierodibello
@xpeppers
By Pietro Di Bello
What we learn using AWS Lambda in a real project, to build an API backend, using Node.JS and the Serverless Framework.
I like to code, test-drive, design, build and run software. I enjoy talking about agile methods, lean software development and more broadly about every principle, practice or process that improve the way we work day by day.