I used altostra to deploy my application to the cloud, and everything is working as expected, but I don’t know how to test my code locally. I’m using API Gateway -> Lambda stack:
screenshot here
I have to deploy my changes to the dev env to test them, which is not ideal. Are there any better ways of local testing using altostra?
In order to test your code locally, Altostra CLI provides two commands alto invoke <function-name> and alto start-api
Invoke command is helpful for invoking lambda functions that expect SNS or SQS events as payload
Start API command is helpful for invoking lambda functions that expect API Gateway payload (Your case) because you can use Postman or other clients to trigger them.
First, you need to compile or build your project, for that, use the alto build command
alto build
After that run
alto start-api
After that, you will see a list of localhost endpoints for your project
Note that for this command to work, you need docker and sam CLI installed
You can also check out this blog post about advanced local testing
Related
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.
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
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.