I am writing AWS Lambda functions for my project (node) and now trying to figure out the best way to deploy these. Ideally I would want to
Convert the ES7 code into a version lambda can understand possibly using webpack.
Deploy using a command line tool or some npm package.
What is the best way to get this done?
You can use serverless and serverless-webpack to do both of those.
serverless is a deployment and configuration tool.
serverless-webpack is a plugin for serverless that will compile your ES7 code upon deployment.
Either you canzip it and upload it or you can use automate the deployment with AWS CodePipelne. Please see here more details about automated deployment
Related
I'm not sure what is the best practice when it comes to AWS lambdas. I have a node 14 lambda that has been running on server successfully. I use terraform to initialize and maintain the code. Do I need to add node engines specifically and buildpacks? It runs fine without them.
No, buildpacks are not required for using Lambda.
It is possible use AWS Code build to create container images using buildpacks, and shipping them to the Lambda container runtime. But that is an optional, and not well-paved path.
I have a few AWS Lambda functions with APIGateway. I'm using the serverless approach, packing and deploying the app using SAM CLI. It outputs the separate function built inside the .aws-sam directory in the project root. I'd like to minify & uglify that source code before the package actually uploads the S3 bucket for deployment. I'm referring to the SAM CLI Docs, but nothing related to customized packaging or using bundlers has been mentioned. Is there a workaround to bundle the sourcecode with minification/uglification?
You can create a custom build runtime described here
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-custom-runtimes.html
or (if you only want to use minification) you can use esbuild
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html
I am trying to debug an AWS Lambda using lambda-local but the problem is that it doesn't recognize imports and exports in node.js.
Is there a workaround other than back-refactoring my entire API to requires?
Imports and exports are not yet supported in Node.
You have two options:
1. Change your imports to use require. Or,
2. Use babel to transpile your code before deploying to Lambda.
If you use serverless-framework, the serverless-webpack plugin will be of big help to you.
I've been using AWS for a while now but am wondering about how to go about developing with Lambda. I'm a big fan of having server-less functions and letting Amazon handle the maintenance and have been using it for a while. My question: Is there a recommended workflow for version control and development?
I understand there's the ability to publish a new version in Lambda. And that you can point to specific versions in a service that calls it, such as API Gateway. I see API Gateway also has some nice abilities to partition who calls which version. i.e. Having a test API and also slowly rolling updates to say 10% of production API calls and scaling up slowly.
However, this feels a bit clunky for an actual version control system. Perhaps the functions are coded locally and uploaded using the AWS CLI and then everything is managed through a third party version control system (Github, Bitbucket, etc)? Can I deploy to new or existing versions of the function this way? That way I can maintain a separation of test and production functions.
Development also doesn't feel as nice through the editor in Lambda. Not to mention using custom packages require to upload anyways. Seems local development is the better solution. Trying to understand others workflows so I can improve mine.
How have you approached this issue in your experience?
I wrote roughly a dozen lambda functions that trigger based on S3 file write event or time, and make a HTTP req to an API to kickstart data processing jobs.
I don't think there's any gold standard. From my research, there are various approaches and frameworks out there. I decided that I didn't want to depend on any kind of frameworks like Serverless nor Apex because I didn't want to learn how to use those things on top of learning about Lambda. Instead I built out improvements organically based on my needs as I was developing a function.
To answer your question, here's my workflow.
Develop locally and git commit changes.
Mock test data and test locally using mocha and chai.
Run a bash script that creates a zip file compressing files to be deployed to AWS lambda.
Upload the zip file to AWS lambda.
You can have version control on your lambda using aws CodeCommit (much simpler than using an external git repository system, although you can do either). Here is a tutorial for setting up a CodePipeline for commit/build/deploy stages: https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-simple-codecommit.html
This example deploys an EC2 instance, so for the deploy portion for a lambda, see here
If you set up a pipeline you can have an initial commit stage, then a build stage that runs your unit tests and packages the code, and then a deploy stage (and potentially more stages if required). It's a very organized way of deploying lambda changes.
I would suggest you to have a look at SAM. SAM is a command line tool and a framework to help you to develop your serverless application. Using SAM, you can test your applications locally before to upload them to the cloud. It also support blue / green deployment and CI/CD workflows, starting automatically from github.
https://github.com/awslabs/aws-sam-cli
I am using serverless to deploy my API on AWS.
In serverless, it allows to deploy a single function:
sls deploy -f <function name>
But it doesn't allow to remove a single function:
sls remove // will remove all functions.
Is there any way to remove single function which won't impact to other functions?
#justin.m.chase suggested:
Simply remove the function in serverless.yml, then run full deploy
sls deploy
the function is removed (Lambda + API Gateway). Perfecto!
I know it's a bit old but the deploy pain of serverless is still a thing.
I recently developed a cli which enables to build microservices in AWS, taking advantage of AWS sam cli (hence the cli name: Rocketsam).
The cli enables caching per function (no more full deploy to the microservice if only one function code changed).
It also has additional features such as splitting the template file to per function, sharing code across functions, fetching logs and more :)
https://www.npmjs.com/package/rocketsam
Currently the cli supports building functions in python 3.6 only, but can be easily extended in the future depending on demand.
As Peter Pham said, remove the function from serverless.yml and do a full:
sls deploy
If you try to delete the function manually in AWS it causes a lot of headaches.
I know this question is over a year old and has been closed but the correct way to remove a single function is to specify it by name which you almost had:
sls remove -f <function name>