| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
| layout | pattern | ||
|---|---|---|---|
| title | Serverless | ||
| folder | serverless | ||
| permalink | /patterns/serverless/ | ||
| categories | Architectural | ||
| tags |
|
Serverless eliminates the need to plan for infrastructure and let's you focus on your application.
Following are optimization katas you should be aware of while building a serverless applications
Whether to reduce your infrastructure costs, shrink the time you spend on ops tasks, simplify your deployment processes, reach infinite scalability, serverless cuts time to market in half.
Serverless computing is a cloud computing execution model in which the cloud provider dynamically manages the allocation of machine resources. Pricing is based on the actual amount of resources consumed by an application, rather than on pre-purchased units of capacity.
Serverless is a toolkit for deploying and operating serverless architectures.
The term ‘Serverless’ is confusing since with such applications there are both server hardware and server processes running somewhere, but the difference to normal approaches is that the organization building and supporting a ‘Serverless’ application is not looking after the hardware or the processes - they are outsourcing this to a vendor.
Some of the Serverless Cloud Providers are
Anything that triggers an Lambda Function to execute is regarded by the Framework as an Event. Most of the Serverless Cloud Providers support following Events
AWS supports processing event generated from AWS Services (S3/Cloudwatch/etc) and using aws as a compute engine is our first choice.
This example creates a backend for ‘persons’ collection which uses DynamoDB NoSQL database service also provided by Amazon.
AWS Lambda SDK provides pre-defined interface com.amazonaws.services.lambda.runtime .RequestHandler to implement our lambda function.
public class LambdaInfoApiHandler implements RequestHandler<Map<String, Object>, ApiGatewayResponse> {
private static final Logger LOG = Logger.getLogger(LambdaInfoApiHandler.class);
private static final Integer SUCCESS_STATUS_CODE = 200;
@Override
public ApiGatewayResponse handleRequest(Map<String, Object> input, Context context) {
}
}handleRequest method is where the function code is implemented. Context provides useful information about Lambda execution environment. AWS Lambda function needs a deployment package. This package is either a .zip or .jar file that contains all the dependencies of the function.
serverless.yml contains configuration to manage deployments for your functions.
Based on the configuration in serverless.yml serverless framework creates following resources
The command will print out Stack Outputs which looks something like this
endpoints:
GET - https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/info
POST - https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/api/person
GET - https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/api/person/{id}
CurrentTimeLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-1:xxxxxxxxxxx:function:lambda-info-http-endpoint-dev-currentTime:4
ServiceEndpoint: https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev
ServerlessDeploymentBucketName: lambda-info-http-endpoin-serverlessdeploymentbuck-2u8uz2i7cap2access the endpoint to invoke the function.
Use the following cURL commands to test the endpoints
curl -X GET \
https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/info \
-H 'cache-control: no-cache'
curl -X POST \
https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/api/person \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"firstName": "Thor",
"lastName": "Odinson",
"address": {
"addressLineOne": "1 Odin ln",
"addressLineTwo": "100",
"city": "Asgard",
"state": "country of the Gods",
"zipCode": "00001"
}
}'
curl -X GET \
https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/api/person/{id} \
-H 'cache-control: no-cache'
| Back | FazBrowse Home | New Git URL |