Lambda function created by Serverless framework includes other folders from root - serverless-framework

Is there a way I can exclude the readme file and sls-templates (which contains my other serverless code) folder from getting uploaded to lambda? I deployed using the serverless framework and it is kind of weird to see my other serverless templates files showing up. Not a big deal though I'm just worried about the size in case my Serverless code base expands.

Absolutely. You can manually include or exclude files in your serverless.yml.
package:
exclude:
- node_modules/**
See more here:
https://www.serverless.com/framework/docs/providers/aws/guide/packaging/

For those whom above explanations might not be matching, this source also outlines it well https://filip5114.github.io/sls-manage-function-package/

Related

Reduce code size of my Express application

I've been using the Serverless framework to deploy my Express application. I used their Express starter template but since I've added code, when I try to deploy it says: Your code size must be less than 200MB. Try using Webpack, Parcel, or AWS Lambda layers to reduce your code size.
I've looked everywhere for a way to use Webpack to reduce my code size but have had no luck.
How can I use Webpack to make my code smaller than 200MB? Again, outside of more endpoints, my code is identical to this: https://github.com/serverless-components/express/tree/master/templates/express-starter
There are some options possible.
check if whats needs to be ignored(PACKAGES) is really ignored.
maybe you installed some packages that are taking too much space.
that's the main reasons for something like that.
Let me add also some points.
as #Ethanolle pointed - clean up your npm dependencies.
Include only used dependencies in your lambda build.
Take advantage of using npm devDependencies.
Consider using the webpack for creating your bundle - serverless-webpack plugin
As an alternative for webpack you may get the benefit of using the more precise configuration of Serverless how to manage what to exclude/include in a bundle

Cloud Run doesn’t work with Express static middleware

I have an express container that serves static files and it works perfectly when built and deployed locally. However, when I build and deploy it to Cloud Run, the dynamic html is returned but static assets like css files are 404. Are there any known limitations with Cloud Runthat May be contributing to this difficult-to-diagnose issue?
Searching the problem, I found this issue and realize the correct answer is masked because it's in the last comment on SO.
Google cloud use a file called .gcloudignore to not ignore some files while uploading.
If the file does not exist, .git and .gitignore files are used, and typically some assets will be in your .gitignore.
https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore

export and maintain vue application

I have developed a vue application and did run npm run build
After that I uploaded the content in the dist file to my webpage but it returned a blank page.
Since I did this for testing I uploaded it to a folder in my public_html/mypage.com/vueapplication To get all the paths right I added a vue.config.js with this content:
// vue.config.js
module.exports = {
publicPath: '/vueapplication/'
}
The application now works but I wounder however:
how do I best publish/upload the application to my site? Just by simply dragging the content inte the right folder?
how can I best maintain my site? Do I need to build again and upload, overwriting my files when everytime I make an update on my site?
And what is the difference between build and deploy your application?
Drag and dropping your code should work. But as your app grows you may want to look into automating this. For instance if you use an S3 bucket you can use the aws cli to automate the upload.
Yes, you should overwrite your deploy folder(s). You need to also take care of deploying different binary files, that have the same name. An example is if you have a global css file (main.css for instance). The file will probably change content between deployments, but keep the same name. Browsers may cache the file so users that downloaded older versions of the file will not use the new one. There are different techniques to handle this, but if you use webpack, it uses cache busting techniques and you should be fine.
Build is the process of transforming source code into an artifact(s). Exactly what this means differs from language to language, platform to platform. In the vuejs world this usually means a couple of js files, a couple of css files and some assets.
Deploying means taking the output of a build and making it available to your users. Again this differs from project to project. In the vuejs world this usually means taking the artifacts from the build and uploading them to an http enabled web server.

Is there a way to generate YAML instead of JSON CloudFormation templates using the Serverless Framework?

The Serverless framework is such a great tool. I use it wherever possible.
I would like to know if there is a way to update the serverless.yml file to output yaml instead of json when generating CloudFormation templates. In the .serverless folder they are in json format but would really be great if they can be auto-generated to yaml instead.
I would not prefer to use great tools like https://www.json2yaml.com/
Any help greatly appreciated.
There's always a way but the simple end-user answer is no.
The serverless-framework has a naming strategy file per provider and for AWS its hard-coded to cloudformation-template-[create|update]-stack.json. When the file writer does its job it looks at the extension and runs the JSON writer.
However as per the AWS naming file in their repo, they've made it available to be modified by writing a custom plugin. As long as your plugin changed the naming strategy to anything that ends in .yml the file writing service will switch to a YAML writing strategy.

Dropwizard serve external images directory

I have a dropwizard API app and I want one endpoint where I can run the call and also upload and image, these images have to be saved in a directory and then served through the same application context.
Is it possible with dropwizard? I can only find static assets bundles.
There is similar question already: Can DropWizard serve assets from outside the jar file?
The above module is mentioned in the third party modules list of dropwizard. There is also official modules list. These two lists are hard to find maybe because the main documentation doesn't reference them.
There is also dropwizard-file-assets which seems new. I don't know which module will work best for your case. Both are based on dropwizard's AssetServlet
If you don't like them you could use it as example how to implement your own. I suspect that the resource caching part may not be appropriate for your use case if someone replace the same resource name with new content: https://github.com/dirkraft/dropwizard-file-assets/blob/master/src/main/java/com/github/dirkraft/dropwizard/fileassets/FileAssetServlet.java#L129-L141
Edit: This is simple project that I've made using dropwizard-configurable-assets-bundle. Follow the instructions in the README.md. I think it is doing exactly what you want: put some files in a directory somewhere on the file system (outside the project source code) and serve them if they exist.