Are there any emulator for AWS Lambda? - amazon-web-services

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.

Related

AWS SAM Local vs Serverless-offline

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.

Is there a way to containerized a normal AWS Lambda function?

My AWS lambda functions have input from AWS SNS (Topic subscription) and output will go to CRUD in NoSQL Database (likewise MongoDB).
So currently I have the SNS & Lambda function setup in AWS Cloud and they are working fine. However, I would like to containerize the lambda function as well as the MongoDB database and host them on AWS EKS using Docker + Kubernetes service. (So the functions will be a Docker image)
I am totally new to this container thing and I searched online though I could not found any that mentions how to containerized AWS Lambda Functions.
Is this possible? If it is what are the ways to do it?
Thank you.
The docker environment for AWS lambda function already exist and it is lambci/lambda. So if you want to run/test your functions locally, this is the tool normally used for that:
A sandboxed local environment that replicates the live AWS Lambda environment almost identically – including installed software and libraries, file structure and permissions, environment variables, context objects and behaviors – even the user and running process are the same.
Since its open-sourced, you can also modify it if it does not suit your needs.
Lambda already uses Firecracker a microVM technology. So, not really sure why it's required to create a container out of Lambda.
The beauty of Lambda/Serverless is to simply write the function code and forget about the rest. If it's all about more control, then look at Knative which runs on top of K8S.

Serverless framework CLI vs GUI. Eg. AWS console

Why would anyone use Serverless framework CLI to write the lambda functions or deploy them when we have AWS console GUI? Are there any specific benefits out of it?
Normally you don't develop and deploy a lambda function in isolation, instead it is one part of your cloud infrastructure. That can include other lambdas, S3 buckets, databases, API Gateways, IAM roles, environment variables and much more.
Serverless framework is allows you to write your infrastructure as code. For AWS services, it translates serverless.yaml config files into AWS cloudformation files, and from there deploys any new or updated services you define. You lambda function is just one part of that.
A major benefit of writing and deploying this way is that you can use your favourite editor locally, and can check your code into version control (i.e. git). This is not just for your lambda code, but also your infrastructure config i.e. serverless.yaml and associated files.
The Serverless Framework is more than just a replacement for the AWS Console (GUI). You can definitely set everything up via the AWS console for a Serverless application but how do you share that with your team? What if you wish to deploy that repeatedly into multiple applications? The Serverless Framework gives you a configuration file, usually called serverless.yml, where you define all the services within AWS (and other vendors, there is support for more than just AWS) and then you use the CLI to perform functions on this configuration file such as deploy, invoke and lot more.
Then there are the Serverless Framework plugins designed by the community around the project to make other tasks even easier such as unit testing, configuration of S3 buckets, CloudFront and domains to make frontend deployment easier and a lot, lot more.
Lastly, but most importantly, there is a professional product provided in addition to the open source framework that you can use to add on monitoring, deployment management, troubleshooting, optimisation, CI/CD and too many other benefits to list here.
Definitely, if you are doing a big project the Serverless framework has a lot of benefits, imagine you developing an MVC c# project with notepad. How do you feel about that?
The framework are done to make our life ( for developers ) very much easier.

Run golang lambda function locally

I'm trying to develop a lambda that has to work with S3 and dynamoDB.
The thing is that because I am not familiar with the SDK of aws for go I will have lots of tests and tries.
Each time I will change the code is another time I have to compile the project and upload it to aws.
Is there any way to do it locally? pass some kind of configuration that lets me call the services of aws locally, from my computer?
Thanks!
This has to do mostly with golang, other languages like python can run directly on the aws lambda function page, and node has cloud9 support.
You can use the lambci docker image(s) to execute your code locally using the same Lambda runtimes that are used on AWS.
https://github.com/lambci/docker-lambda
You can also run dynamo DB locally in another container as well
https://hub.docker.com/r/amazon/dynamodb-local/
To simulate credentials/roles that would be available on Lambda, just pass in your Api creds VIA environment variables. ( for s3 access )
Cheers
-JH
You could use this aws-lambda-go-test module which can run lambda locally and can be used to test the actual response from lambda
full disclosure I forked and upgraded this module

AWS with Serverless Framework EC2 deployment

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.