We are a Terraform shop for standing up our infrastructure on AWS and I am using AWS SAM Local to:
Test AWS Lambdas locally without having to deploy on the cloud.
I can also run integration tests on locally running lambda function as it will call downstream services that are running in the cloud.
I am curious about serverless-offline. I don't have much experience with the npm serverless library and wondering if others have any experience how it compares to SAM Local? Does it have same capabilities that I am able to accomplish with AWS SAM Local?
The sam local cli command and the Serverless Offline plugin work in similar ways. Both run a Docker instance and emulate API Gateway and Lambda. Additionally, Serverless Framework supports other platforms, unlike SAM Local.
The biggest advantage of using one or another is the ability to test your Serveless functions locally with the tool that you are currently using. So if you are using AWS SAM, the sam local will be the best option, similar if you are using the Serverless Framework, as the best option will be using the Serverless-offline plugin.
Serverless Framework included offline testing long before SAM Local arrived, so maybe you can find options that are not available yet using SAM local. sam local can have some advantages, such as template validation.
Both systems use Node.js and support API Gateway and Lambda, but neither currently supports DynamoDB execution, so you need to work in a way to make your DynamoDb available locally.
If you want to decide if the best option for you is the AWS SAM or the Serveless Framework, you can take a look in comparison like this one: Comparing AWS SAM with the Serverless framework.
Related
I have joined a project where I have written AWS Lambda Functions in C#. I'm new to working with AWS and Lambda Functions. Does anyone know of a way of automating releases into AWS? Can scripting be applied to releasing without a pipeline? The only option I have found so far is to upload the code in a zip file. Is there a better method of deployment?
Deployment Methods are plentiful.
You can use Terraform, it works well enough using an SDK in your language of chocie.
In-house to AWS, you have CloudFormation Templates which can be applied through CodeDeploy as part of a CodePipeline (since you mention c# you are using a docker deployment of lambdas, you may need a codebuild step.)
The next level up from that is SAM Templates, which I believe will handle a docker deployment of a C# lambda much easier than CloudFormation by itself would.
Finally you have the CDK (Cloud Development Kit) which puts infrastructre as a language, and allows you to program your infrastructure in most languages (I Do not know if C# is one of them - Typescript, Python are the two more popular ones to do CDK in) and I believe that can handle Docker deployment of lambdas as well.
It appears that SAM is implemented in the Serverelss framework; however, I am unable to find any documentation on this based on the lack of documentation from server less framework compared to AWS. AWS goes in to depth with SAM (as I am studying for the test) but I use serverless framework for my deployments and I'm trying to figure out the difference between the configuration file between the two.
They are related but are not quite the same thing. SAM and Serverless Framework are both layers on top of CloudFormation (when deploying to AWS; Serverless works with other providers too). They abstract away some of the things that make defining serverless applications in CloudFormation hard, but code written for SAM won't work with Serverless Framework, and vice versa. SAM templates can also have CloudFormation templates embedded in them. In that regard they are an extension or a superset.
Another difference is that SAM provides some tools for running functions locally and debugging them.
We are planning to deploy our API to AWS Lambda, and for local development, we use Serverless framework with Serverless Offline. Can we deploy the same serverless APP to dedicated server instances as we have some requirements where the same APP could be deployed in server as well. Can i use serverless-offline to run it. Or do we have any better mechanism . By the way we use Node JS.
This really depends how you have your code setup, we use hapi to map the requests from lambda to a specific handler and we can also use hapi to run a server. The only effort that we had was to include a middleware to convert the lambda event to a request so that we can use the same handlers.
Here's something that we based our approach:
http://www.carbonatethis.com/hosting-a-serverless-hapi-js-api-with-aws-lambda/
I wouldn't use serverless offline to be run in ec2 mainly because serverless offline does not work as a server and certain things don't work as expected when compared to lambdas.
You can deploy the same APIs to Lambda also, For that you need to change your main index file. Or you can create 2 files let say index.js, server.js, where in index file simple Hapi/express code can be used and in server file, lambda function can be used. Routing will be the same for both files. You can use index.js for your local use and for lambda deployment you can use server.js.
I am working to extend this solution https://github.com/adieuadieu/serverless-chrome to my needs.
I am using serverless (on my laptop with Debian 9) to deploy it to AWS Lambda. I would like to use AWS-Sam-local https://github.com/awslabs/aws-sam-local to run it locally for developing.
I would like to use AWS-Sam-local because I believe that there is difference between running this solution via serverless webpack serve --function run and sam local start-api. The difference I think, is event object which I want to make contain POST or binary data (multipart files transfer). For that I have to allow binary transfer via API Gateway.
But correct me if I am wrong because I am totally green in the AWS and Serverless field and this is my first time with this technologies.
The problem I get is aws-sam-local needs the CloudFormation template to know how to run serverless-chrome project. If I make deploy to AWS and go to CloudFormation Console I can copy that template after selecting it in "Stacks" table and clicking "Template" tab. Then I use cfn-flip to convert JSON into YAML. In the end I got template.yml, but running sam local start-api gives me error:
2017/10/06 11:03:23 Connected to Docker 1.32
ERROR: No Serverless functions were found in your SAM template.
Please tell me what to do to make serverless-chrome run locally as it would run on AWS Lambda.
The templates Serverless uses to deploy are available in two places:
Remotely, in the S3 deployment bucket
locally, in .serverless/
I want to run Go service on AWS Lambda by this instruction without actually using AWS Lambda service. Looking for a vagrant or vbox which can emulating Lambda. I know it's a weird request. Is it possible?
There are a few options (from damn simple to more complete)
Node Lambda – Command line tool to locally run and remotely deploy your node.js applications to Amazon Lambda.
Custom event used to simulate an input similar to what Lambda would get on AWS.
Allows testing locally, simulating AWS Lambda environment.
Deploy
grunt-aws-lambda – Grunt plugin to assist in developing functions for AWS Lambda.
All of the above
Function packaging (ZIP)
Separation of environments (dev, test, production)
Adds stripping and packaging of function before deploying (including only necessary packages).
serverless (formerly JAWS) – Complete application framework to build applications based on different services in AWS (that relies heavily on AWS Lambda).
All of the above
Includes boilerplate setup
Simulates an API gateway to test locally
Hope this is useful.