Serverless Offline for testing on your local machine. Tutorial with DynamoDB

  Рет қаралды 35,254

Complete Coding - Master AWS Serverless

Complete Coding - Master AWS Serverless

4 жыл бұрын

Playlist Available Here:
• Production Ready Serve...
In this video we'll be learning to set up serverless-local. This allows us to test that our code is working without having to deploy it onto AWS. This means you can test your changes faster so you end up building features quicker.
Install the Java Runtime Engine (needed for Dynamo)
www.oracle.com/java/technolog...
Code Available Here:
github.com/SamWSoftware/Serve...

Пікірлер: 96
@jimishshah82
@jimishshah82 4 жыл бұрын
You are a superstar, Thanks you very much for your videos.
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Glad you like them!
@hellaren
@hellaren Жыл бұрын
Thank you for your remarkable videos!
@nayeemurrehman4922
@nayeemurrehman4922 3 жыл бұрын
Great work 👍
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Thank you so much 😀
@JeanYvesP
@JeanYvesP 4 жыл бұрын
Awesome! Thanks!
@CompleteCoding
@CompleteCoding 4 жыл бұрын
I'm glad you enjoyed it
@madhavareddy3488
@madhavareddy3488 Жыл бұрын
Thanks! This helps!!
@CompleteCoding
@CompleteCoding Жыл бұрын
Gald it's useful
@MrRobinkv
@MrRobinkv 2 жыл бұрын
Very useful
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Glad you think so!
@MrHossamsaraya
@MrHossamsaraya 3 жыл бұрын
Great guy
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Thanks :)
@ivoneijr
@ivoneijr 3 жыл бұрын
Awesome! thks!
@CompleteCoding
@CompleteCoding 3 жыл бұрын
No problem!
@PeteWhelan
@PeteWhelan 4 жыл бұрын
Hi sam - thanks for the great videos again I plan to work through the production-ready series this week. In this video, you have included a plugin called serverless-webpack to the code in the yml. I can't find where you put that into the program on any of the previous tutorials - can you point me in the right direction with a link to the tutorial that you introduce it, please? Thanks.
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Hey Pete, Just looked through all of my videos and realised that I never uploaded my webpack video. I'll do that this week but for now heres a summary Short summary: We use webpack as by default serverless uploads all the code from the repo into every lambda. When you have lots of code (10-15 endpoints and lots of common code) you hit the upload limit of the lambda. Webpack works to only include the code that you need, reducing the upload size. Steps to setup: npm install --save-dev webpack serverless-webpack add serverless-webpack to the plugin list add this to your serverless.yml file package: individually: true Create a webpack.config.js file at the root of your repo containing this module.exports = { target: 'node', mode: 'none', };
@PeteWhelan
@PeteWhelan 4 жыл бұрын
@@CompleteCoding thanks Sam I have that working in the code now but I can't get the offline dynamodb to start in the final step. Everything else works. The error seems to point to (!child.pid) - any idea where I'm going wrong? Could it be something to do with the Java developer kit? It's not clear in the video what role that plays.
@PeteWhelan
@PeteWhelan 4 жыл бұрын
Error -------------------------------------------------- Error: spawn java ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19) at onErrorNT (internal/child_process.js:407:16) at process._tickCallback (internal/process/next_tick.js:63:19) For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
@CompleteCoding
@CompleteCoding 4 жыл бұрын
@@PeteWhelan Have you installed the Java Runtime Engine? www.oracle.com/java/technologies/javase-jre8-downloads.html
@PeteWhelan
@PeteWhelan 4 жыл бұрын
@@CompleteCoding Thanks Sam - the following steps solved this issue. I downloaded the java engine from the link, rebooted my computer. Deleted DynamoBd folder from the code and reinstalled DynamoDB PS on your video and Github code - you have "ProvisionedThoughput", I've assumed that is a typo and have replaced with "ProvisionedThroughput" in the player-score.json. Looking forward to the next video. :)
@dularamalindu427
@dularamalindu427 2 жыл бұрын
Hi, An amazing tutorial. I also checked the github code. but which branch should I check for this tutorial?
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Thanks Here's the link github.com/SamWSoftware/ServerlessKZfaqSeries/tree/l19-serverless-offline
@costagiannakopoulos2575
@costagiannakopoulos2575 Жыл бұрын
Great video, I am using serverless offline for my gql lambda so I can run some automated tests against it. When running jest test’s sequentially they all pass but when I run them in parallel the offline lambda fails and shuts down. Do you have any tips on how to solve this? Thanks
@ArturBanul
@ArturBanul 3 жыл бұрын
Hi, I just watched you video. It was really helpful. One thing is not clear to me. Why did you created player-score.json file and added there table defininition which was already in serverless.yml? Why this table definition is duplicated?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
You no longer need to create that file. Serverless now takes the definition straight from the serverless file
@usamashahid3172
@usamashahid3172 2 жыл бұрын
@@CompleteCoding I have completely opposite issue, I dont want to define table in yml file, since it is already deployed through another service. Is it possible? or can I make serverless.yml to ignore the table while deploying and only use it for testing?
@CompleteCoding
@CompleteCoding 2 жыл бұрын
@@usamashahid3172 There should be a way to do that but it's not simple and would be easier if you were using serverless.ts create a new js/ts file just for your dynamo config. In that file it needs to be a function that takes the serverless config as a parameter. That function should check if this is running as a deployment or running locally and return either no resources when deploying and the dynamo table resource when running locally. I've never had to do this but it should be possible
@combinedaccount5774
@combinedaccount5774 3 жыл бұрын
Hi, Can you make a video or explain about debugging in serverless-offline using VSCode?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
That's a great idea. I'll add it to the list
@tienlevan1817
@tienlevan1817 3 жыл бұрын
Hi Sam, Thanks for the great video. I have a problem, I can see the response as in console.log. But i can't find the response in POST MAN app. Can you help? Thanks.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
That's strange. I would check that you are calling the response function with all the data you want to be returning.
@theinnoverse
@theinnoverse Жыл бұрын
Hey Sam this is good but don't you think sls invoke is much easy? And what would you prefer? And why?
@CompleteCoding
@CompleteCoding Жыл бұрын
I've changed my opinion on this since making the video. I mainly do end to end testing once it's been deployed. I either have a 'dev' environment or a temporary one. Offline is ok if your app is super simple ( just API and Dynamo) but once you add any other services, trying to mock things becomes too messy
@VasylHerman
@VasylHerman 3 жыл бұрын
Hi, Sam! Do we need JDK or JRE and whick version ?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
The link is in the description
@xmelsky
@xmelsky 3 жыл бұрын
@Complete Coding Hey, there is a small update. Actually IS_OFFLINE property has been restored. I've tried it - and it works just fine
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Awesome to hear. I'll update the description
@jimishshah82
@jimishshah82 4 жыл бұрын
I was getting `Error: spawn java ENOENT` so had to do `sls dynamodb install` which fixed the issue
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Glad that you figured out how to fix it :) well done
@Saswatxp
@Saswatxp 3 жыл бұрын
Hi Sam Do you have examples in java to configure serverless offline?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
I've never worked in Java and I think that it might be more difficult as lambda doesn't natively support java. You could look into the new serverless containers (docker) to run your java code
@CompleteCoding
@CompleteCoding 4 жыл бұрын
If you get an error with this process, check the version of serverless-offline that you have installed. There has been a change in V6 that breaks this process. To resolve it, update to the latest version of serverless-offline
@joostschuur
@joostschuur 3 жыл бұрын
Looks like in recent versions of serverless-offline, they've added process.env.IS_OFFLINE support back in.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
@@joostschuur Yes I was amazed to see that
@JeanYvesP
@JeanYvesP 4 жыл бұрын
Is there anyway to debug locally with debugger and breakpoints?
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Yes you can. If you are using VS-Code then you can stick breakpoints wherever you like. You can then use the built in debugger to run all of your tests, stopping at the breakpoints so you can view the variables at that point. completecoding.io/content/images/2020/03/Screenshot-2020-03-06-at-07.29.36.png
@juanjoseramirezcalderon2618
@juanjoseramirezcalderon2618 2 жыл бұрын
@@CompleteCoding do you have a video with the setup for vscode debugging?
@CompleteCoding
@CompleteCoding 2 жыл бұрын
@@juanjoseramirezcalderon2618 I do actually kzfaq.info/get/bejne/rsdydL2el9DKiIU.html
@ofirmagen4224
@ofirmagen4224 2 жыл бұрын
Hi Sam .. Hopefully you're still following comments on this video. I just inherited a big serverless project that all of the dynamoDB tables were created on AWS directly (as opposed to having a resource in the serverless.yml file). Can I still run serverless-dynamodb-local w/out creating that json file (like your player-score.json)? If not, do you have an idea how I can grab the json version (keyschema, etc..) from an already running dynamoDB table?
@CompleteCoding
@CompleteCoding 2 жыл бұрын
You would have to create a dyanmoDB table config for each of the tables you use to get it working with serverless dynamo local. You would then have to add some logic to the table so it doesn't actually try deploying it - as you would be trying to create a table that already exists. You can use "conditions" in cloudformation to do that. "Conditions": { "CreateDynamoResources": { "Fn::Equals": [ { "Ref": "EnvType" }, "test" ] } }, "Resources": { "DynamoTable1": { "Type": "AWS::DynamoDB::Table", "Condition": "CreateDynamoResources", "Properties": { ... } },
@pravallikak7794
@pravallikak7794 2 жыл бұрын
@@CompleteCoding can't we use serverless-dynamodb-local and write the code without AWS credentials?
@pravallikak8794
@pravallikak8794 2 жыл бұрын
Hi Sam @complete coding , where do this data gets stored locally ?
@CompleteCoding
@CompleteCoding 2 жыл бұрын
It runs a local dynamodb table on your machine. So the data is technically stored in the ram of your computer.
@cristianecheverria3995
@cristianecheverria3995 4 жыл бұрын
I was having issues running "serverless offline" with "webpack". Something saying "serverless offline ERROR in Entry module not found: Error: Can't resolve './src'" and wasn't possible to test locally using Postman. I found a solution with this code inside webpack.config.js. Because it seems like was looking for "./src" folder as the entry point. //webpack config const slsw = require("serverless-webpack") module.exports = { entry: slsw.lib.entries, target: "node", mode: "none", } I'm using "serverless-offline": "6.4.0"
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Yes, this video was recorded back when it was serverless-offline 5.x and that didn't require this change. I'll add something to the description to outline this
@alashish
@alashish Жыл бұрын
Hi, great video man i just have 1 issue now my vs code debugger don't work.
@gasparh1886
@gasparh1886 3 жыл бұрын
Hello, when I run your example I get "error in dynamo write Error: connect ENETUNREACH" "'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1" I am stuck here, thanks
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Have you set up an aws credentials profile on your computer? It appears to be looking for the correct AWS credentials to use.
@abdoualgerian5396
@abdoualgerian5396 3 жыл бұрын
Hi , why did you name the json file player-score.json ?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
You can call it what you want. It could just be called 'player-points.json' or anything els
@BELLA-cf9md
@BELLA-cf9md 3 жыл бұрын
Any video using Go Lang? instead of Node.js
@CompleteCoding
@CompleteCoding 3 жыл бұрын
I've worked in Go a little bit but not enough yet to be confident making videos on it. The serverless parts of my videos should be the same, just with a change in the actual lambda file
@shwenansuwai2481
@shwenansuwai2481 4 жыл бұрын
It is working normally at my friend's PC.... I do not know what happened... At my side, I still receive this message [Serverless-Offline] Your lambda handler 'createPlayerScore' timed out after 30000ms. by testing with postman / insomnia / curl command ... Any advice is much appreciated on how to fix this?
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Check the code in your lambda. Make sure that there isn't a loop or something in the code. If it is a request with Dynamo, make sure that you'e installed `sls dynamodb install`. There is also a change with v6 of the serverless offline plugin where process.env.IS_OFFLINE doesn't exist. If you add a console.log to the code and log out that variable you should see what it's value is. If it is undefined then you can resolve this by changing the version of serverless-offline (in you package.json) file to 5.12.1, deleting node modules and package-lock and running `npm install` again
@shwenansuwai2481
@shwenansuwai2481 4 жыл бұрын
​@@CompleteCoding just got it ... thank you very much ... you saved my life SAM ...
@dhanwadc
@dhanwadc 4 жыл бұрын
Ist view
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Well done Dhanwa
@udaysingh7748
@udaysingh7748 3 жыл бұрын
Hi,Using express it is giving error { "currentRoute": "get - /api/user", "error": "Serverless-offline: route not found.", "existingRoutes": [ "* - /api" ], "statusCode": 404 } It is only with express!!!!!
@CompleteCoding
@CompleteCoding 3 жыл бұрын
I've never worked with Serverless and Express but I think I know the issue. If you run 'sls info' what urls do you get? If you don't get "someapi/{stage}/*" then you might need to change the paths in your function definition I'm assuming you have one function with all your express logic in? It should look something like this ExpressFunction: handler: src/ExpressFunction.main events: - http: path: * method: ANY cors: true
@alifarah9
@alifarah9 2 жыл бұрын
is there a way to set breakpoints?
@alifarah9
@alifarah9 2 жыл бұрын
never mind you have a full video on this
@CompleteCoding
@CompleteCoding 2 жыл бұрын
This is something that I've started to do a lot more in my lambda development
@Passion4CoolMusic
@Passion4CoolMusic 3 жыл бұрын
i get " Serverless command "offline" not found. Did you mean "config"? Run "serverless help" for a list of all available commands."
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Have you installed the plugin and added it to the plugin list? www.serverless.com/plugins/serverless-offline
@ddsmax
@ddsmax 2 жыл бұрын
Where's the offline folder in the code repo?
@CompleteCoding
@CompleteCoding 2 жыл бұрын
You don't need a whole folder for offline, just adding "serverless-offline" as a plugin in the serverless.yml file. I've also used "serverless-dynamodb-local" in this video for running Dynamo local as well
@ddsmax
@ddsmax 2 жыл бұрын
@@CompleteCoding You are missing the offline/migrations folder in the code repo for this video. The repo for the next video in this playlist has the folder.
@CompleteCoding
@CompleteCoding 2 жыл бұрын
@@ddsmax You don't need that folder. Dynamo-local will automatically use the Dynamo config in your resources file to create the local table. If you are connecting to a dynamo table that you don't create in that repo you can use this migrations folder. I need to delete it from the next repo as it's not needed
@leugimsimara
@leugimsimara 3 жыл бұрын
Hey, thank you for the tutorial, pretty cool. Take a look at the httpie lib, it has saved me several hours: httpie.org, you can do things like `http post :15001/create-player-score/1234 name=Sam age:=23`. Cheers!
@CompleteCoding
@CompleteCoding 3 жыл бұрын
That looks like a really smooth library. Do you know if there is any history of requests? One of the things I do most in postman is searching through old request to re-use one.
@devilssoccer1
@devilssoccer1 3 жыл бұрын
IS_OFFLINE env variable is back with v6.3.0! github.com/dherault/serverless-offline/commit/8755d9da8d26cc61a4239d5edd14cc4387d46349
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Awesome to hear
@RomeoMihalcea
@RomeoMihalcea 3 жыл бұрын
Say serverless one more time. I double-dare you.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Haha :P It's so hard to do a video on Serverless without saying it all the time
@nichenjie
@nichenjie 4 жыл бұрын
IS_OFFLINE is removed in the recent versions github.com/dherault/serverless-offline/commit/331f5418d7c5c9811354a3438388bb098ef4cb38
@CompleteCoding
@CompleteCoding 4 жыл бұрын
I know, it is very frustrating. You can install version 5.12.1 of serverless offline which still works. I'll comment again when I have a solution to resolve this.
Unit Testing in Serverless - tutorial including DynamoDB
27:24
Complete Coding - Master AWS Serverless
Рет қаралды 15 М.
How to debug Serverless from within VS Code
17:40
Complete Coding - Master AWS Serverless
Рет қаралды 16 М.
Alat Seru Penolong untuk Mimpi Indah Bayi!
00:31
Let's GLOW! Indonesian
Рет қаралды 16 МЛН
Каха и суп
00:39
К-Media
Рет қаралды 4,3 МЛН
Adding Serverless Webpack to your Project - fix Lambda Upload Limits
10:23
Complete Coding - Master AWS Serverless
Рет қаралды 16 М.
I think I was wrong about AWS Amplify
30:39
Web Dev Cody
Рет қаралды 56 М.
Getting Started with Serverless Framework
20:53
Serverless
Рет қаралды 30 М.
AWS API Gateway Websocket Tutorial With Lambda | COMPLETELY SERVERLESS!
19:07
Amazon DynamoDB Using Java
16:44
Tapas Joshi
Рет қаралды 20 М.
Deploy FastAPI on AWS Lambda ⚡ Serverless hosting!
22:24
pixegami
Рет қаралды 37 М.
How to write Integration Tests for Serverless AWS Endpoints - API Gateway and Lambda Guide with Jest
33:04
Complete Coding - Master AWS Serverless
Рет қаралды 16 М.
Setup AWS Serverless Project with Typescript Lambda Functions
28:43
How to Query Your DynamoDB Table with SQL using Athena
26:13
Be A Better Dev
Рет қаралды 13 М.
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,6 МЛН
ОБСЛУЖИЛИ САМЫЙ ГРЯЗНЫЙ ПК
1:00
VA-PC
Рет қаралды 1,7 МЛН
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 6 МЛН