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/
Related
I have set up a lambda function using AWS Sam CLI that I am using for local development. After development, I have deployed this function to AWS console for production from my IDE (visual studio code). After deployment, when I see It has created several other resources such as cloudformation, Api Gateway, and a few others.
What's problem?
I am seeking a way through which I can deploy only my Lambda code that doesn't create other resources like Api gateway, etc. Is there any way that allow me to only create lambda function on local environment and then I want to push my code to AWS console.
Moreover, when I use AWS Sam the size of my Lambda code also increased incredibly. When I created the same Lambda manually on AWS Console it consumes only a few kbs but when I created Lambda using AWS Sam it's size ramped up to 25MB.
If someone know a better way to do this please elaborate.
You can see my concerns the following:
Create Lambda function on local machine for development
I don't want to shift my Lambda function manually from local environment to AWS Console.
Also assign the Lambda function with specific permissions
What are the best practices for this? If someone is still confuse please ask anything in the comment section.
Use local devtools which simplify cloud infrastructure local development and automate the process of deployment.
Check for example Altostra local devtools:
VS Code extension to build AWS infrastructure in visual way, including configuration of each AWS resource (extension is available on official VS Code marketplace)
CLI (available on official npm marketplace) - automatically package all your code and cloud infrastructure and push it to your AWS account. After push you can also deploy your project directly from your local dev environment to AWS - Altostra automatically generates CloudFormation from your visual design and deploy the stack to your AWS account. All permissions are generated automatically as well.
Notice, you need to open an account on Altostra to be able to do all described in #2 (account is free).
You can upload your application to aws lambda in 3 way :
1- Create a zip file and upload via console (project files can not exceed 250mb)
2- Upload your files to s3 and reference it (doable)
3- Create docker images and upload it (the easiest way)
The best way is to upload as container images because you can upload files/dependencies up to 10gb inside the docker image.
After you create your docker images, you can test it locally too. Please check :
https://docs.aws.amazon.com/lambda/latest/dg/images-test.html
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 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.
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
I am trying to deploy Lambda functions using AWS Cloud9. When I press deploy, all of my functions are deployed/synced at the same time rather than just the one I selected when deploying. Same thing when right clicking on the function and pressing deploy. I find this quite annoying and wondering if there is any work around?
When you click deploy Cloud9 runs aws cloudformation package and aws cloudformation deploy on your template.yaml file in the background. (source: I developed the Lambda integration for AWS Cloud9).
Because all your files are bundled into one serverless application and there is only one CloudFormation stack they can only be all deployed at once with CloudFormation.
If you're only making a code change for one function and are not modifying any configuration settings you could update that one function from the command line with the command:
zip -r - . | aws lambda update-function-code --function-name <function-name>`
Run this in the same folder as your template.yaml file, replacing <function-name> with it's full generated name like cloud9-myapp-myfunction-ABCD1234 (You can see the full name under the remote functions list in the AWS Resources panel).
In AWS Cloud9, Lambda functions are created within serverless applications and are therefore deployed via CloudFormation. With CloudFormation, the whole stack is deployed at once, so all functions are deployed together (see this discussion for more info).