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
Related
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.
I'm new to AWS and for learning purpose I created a free AWS account. I don't want to install all dependencies, packages and configure them with my test account in my pc until I learn them well. So I planned to create a docker image so I can do configurations later in my pc. But I can't find any good example how to set up docker image for AWS Lambda. Can you please help me to set up docker image?
p.s
I'm using NodeJs
Check out https://github.com/localstack/localstack - A fully functional local AWS cloud stack (Lambda as well).
The solution will depend on language you are going to use for lambdas.
Try some tutorials, i.e. the next descibes how to simulate lambda for python:
https://aws.amazon.com/premiumsupport/knowledge-center/lambda-layer-simulated-docker/
Recent AWS blog describes how to do it:
How do I create a Lambda layer using a simulated Lambda environment with Docker?
Basically you can run already made docker image for that:
https://hub.docker.com/r/lambci/lambda/
This is the same docker image used by AWS's SAM (Serverless Application Model) when you test your lambda function locally. Thus this is the closest you can get to the real lambda environment.
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.