Package or zip archive creation with serverless but without lambda - zip

It is needed to create zip file before deployment and there is no lambda functions. Just some folder to zip and upload. Without functions: section serverless skip packaging. Any ideas? Any work arounds?

The Serverless Framework generates two things, a zip file containing the code of your Lambda function(s) which is zipped and uploaded to AWS, and the CloudFormation JSON template which is sent to the CloudFormation API.
If you don't have any functions, there are no artifacts/code to zip - so packaging is not necessary.
As your stack only contains CloudFormation - you can simply run serverless deploy to apply those changes.

Related

AWS Serverless: minify/uglify the sam build lambda output

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

AWS CloudFormation with node.js 10.x Update Error "ZipFile can only be used when Runtime is set to <older node.js versions>"

We are using CloudFormation template to deploy some intermediate code on Lambda function.
We are using ZipFile function to add inline code through CloudFormation.
Current runtime for lambda function is node.js 8.10.
We need to update node version to 10.x.
While updating Lambda using cloudformation we are getting below error:
ZipFile can only be used when Runtime is set to either of nodejs,
nodejs4.3, nodejs6.10, nodejs8.10, python2.7, python3.6, python3.7.
I believe that this is a known issue. https://forums.aws.amazon.com/thread.jspa?threadID=303166&tstart=0
As of this writing, it is still an issue. My suggestion is to have super basic code in an S3 bucket and reference that instead of using a zip file and deploy your actually code after the lambda function is created. Alternatively, you can just upload your zip artifact to an S3 bucket. If your code is proprietary be careful about S3.

Online-Edit Amazon Lambda function with alexa-sdk

I am creating an Alexa skill and I am using Amazon Lambda to handle the intents. I found online several tutorials and decided to use NodeJs with the alexa-sdk. After installing the alexa-sdk with npm, the zipped archive occupied a disksize of ~6MB. If I upload it to amazon, it tells me
The deployment package of your Lambda function "..." is too large to enable inline code editing. However, you can still invoke your function right now.
My index.js has a size of < 4KB but the dependencies are large. If I want to change something, I have to zip it altogether (index.js and the folder with the depencencies "node_modules"), upload it to Amazon and wait till its processed, because online editing isn't available anymore. So every single change of the index.js wastes > 1 minute of my time to zip and upload it. Is there a possibility to use the alexa-sdk dependency (and other dependencies) without uploading the same code continually every time I am changing something? Is there a possibility to use the online-editing function though I am using large dependencies? I just want to edit the index.js.
If the size of your Lambda function's zipped deployment packages
exceeds 3MB, you will not be able to use the inline code editing
feature in the Lambda console. You can still use the console to invoke
your Lambda function.
Its mentioned here under AWS Lambda Deployment Limits
ASK-CLI
ASK Command Line Interface let you manage your Alexa skills and related AWS Lambda functions from your local machine. Once you set it up, you can make necessary changes in your Lambda code or skill and use deploy command to deploy a skill. The optional target will let you deploy the associated Lambda code.
ask deploy [--no-wait] [-t| --target <target>] [--force] [-p| --profile <profile>] [--debug]
More info about ASK CLI here and more about deploy command here

Deploying lambda applications on AWS

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

Deploy Lambda functions without binaries

I have some problems with serverless deploy, because when I deploy my Lambda function, the Serverless Framework start packing my node_modules, but it takes a lot of time.
I mean why to upload node_modules again if it have not been updated. Maybe somebody know, how deploy only a Lambda function code without packing binaries?
You need to add packaging configuration.
In your serverless.yml file, add:
package:
exclude:
- node_modules/**
It is useful to remove the AWS-SDK modules (because if you don't upload them, Lambda will use what AWS offers - which is better) and to remove dev modules (like testing frameworks). However, all other modules are dependencies and will be needed to be uploaded for your function to work properly. So, configure the package settings to include/exclude exactly what you need.
Regarding your other question
why to upload node_modules again if it have not been updated
It is not a limitation of the Serverless Framework. It is a limitation of the AWS Lambda service. You can't make a partial upload of a Lambda function. Lambda always requires that the uploaded zip package contains the updated code and all required modules dependencies.
If your deploy is taking too long, maybe you should consider breaking this Lambda function into smaller units.

Resources