No video

Securing Your Serverless API With API Keys

  Рет қаралды 9,982

Complete Coding - Master AWS Serverless

Complete Coding - Master AWS Serverless

Күн бұрын

In this video you'll learn how you can create API keys so you can control who can access your APIs

Пікірлер: 76
@toninotonnato7776
@toninotonnato7776 2 жыл бұрын
Excellent tutorial, clear step by step guide. I wish there were more like this around. Thanks! :)
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Glad it was helpful!
@muralielumalai
@muralielumalai 3 жыл бұрын
your explanations are awesome.!
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Glad you like them!
@abdelhadidjafer7004
@abdelhadidjafer7004 2 жыл бұрын
Hi sam , please note that after the V3 there has been some changes so there need to be a minor changes in this video , i know you have made a video about V3 changes but this one worthy to be mentioned since a very starter would struggle if he didnt know how to fix it , the apiKeys property become now under the apiGateway property now, same for the usagePlan
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Yes, there are quite a few small changes to v3 which make some of my older videos out of date. Unfortunately I can't update existing videos.
@desdemicocinaconamor
@desdemicocinaconamor 2 жыл бұрын
Thanks for pointing this out. I just ran into the issue with apiKeys as I was working through this video. For anyone who wants to see the differences in order to troubleshoot the migration from v2 to v3, they are documented at the serverless.com site: www.serverless.com/framework/docs/guides/upgrading-v3 Also, thanks Sam for putting these videos together! I have been finding them to be well done, concise and still mostly correct despite the passage of 2-3 years by this point.
@CompleteCoding
@CompleteCoding 2 жыл бұрын
@@desdemicocinaconamor Thanks Michael. With Tech moving so fast it is often hard to make content that lasts more than a year
@pavithrab2884
@pavithrab2884 Жыл бұрын
@michael dichirico that was helpful. Thank you:)
@pavithrab2884
@pavithrab2884 Жыл бұрын
Hey Sam, you are awesome and definitely a savior for me .Kudos
@CompleteCoding
@CompleteCoding Жыл бұрын
Happy to help!
@prajwalhalwai1042
@prajwalhalwai1042 3 жыл бұрын
Great work and videos!
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Thank you very much!
@neosarchizo
@neosarchizo 4 жыл бұрын
Thanks for the good video again!
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Always happy when someone enjoys a video
@programmusicuk
@programmusicuk 4 жыл бұрын
Hi Sam, thanks for the excellent FreeCodeCamp Serverless tutorial! The videos have been very clear and easy to follow. Quality videos.
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Thanks! Im, really glad you've found them helpful. Are there any other topics that you would like me to cover?
@programmusicuk
@programmusicuk 4 жыл бұрын
@@CompleteCoding redirects would be good. I'm having difficulty working this out. I want to perform a "success" redirect once a form has been sucessfully submitted.
@CompleteCoding
@CompleteCoding 4 жыл бұрын
​@@programmusicuk If you're building your application in JavaScript (react, vue or html with a JS file) then you need to wait for the response of the form submission. If it succeeds then you can render a different view or redirect the user to a new page using JS
@alexkronfeld2150
@alexkronfeld2150 3 жыл бұрын
@@CompleteCoding Hi Sam, thanks for the great tutorials! Is it possible to add tutorial how to connect websockets and REST APIs with Cognito user pools and provide authenticated and authorized access to Lambdas? Also Federated access example through Google/Facebook will be very appreciated.
@uthpalapitawela7054
@uthpalapitawela7054 3 жыл бұрын
Thank you very much. Great video
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Glad you liked it!
@nielsrozeboom8852
@nielsrozeboom8852 3 жыл бұрын
great tutorials! You deserve a lot of likes! :-)
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Thanks Niels! Glad you liked the video
@shadmanmartinpiyal4057
@shadmanmartinpiyal4057 3 жыл бұрын
Super excellent!
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Thank you! Cheers!
@sergiosepulveda7860
@sergiosepulveda7860 11 ай бұрын
thanks a lot
@marynavatsko9692
@marynavatsko9692 3 жыл бұрын
Thanks for the video, it really helped! Could you make another one to explain more intricate details of dealing with api keys? For example, how to create different keys for different stages, what happens with the key every time you deploy everything, is it possible to pass your own value for the key, etc? Because while the docs are confusing, your explanations are crystal clear and easy to follow) thanks again : )
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Since publishing this video I've actually moved away from the built in API keys and would use another authentication method. If you like the process of API keys then have a Dynamo Table that you store the API key and any other data you might want (remaining capacity, what they have access to). Then you can add a Lambda Authoriser to check the API exists and has the properties needed (access to the requested resources). You could also use another auth method like Cognito. This works really well when users are accessing your systems through a website. They sign up and you create them a user. You can then just use that cognito user pool as the authenitcation method for the Lambdas.
@humphreyquaye1087
@humphreyquaye1087 2 жыл бұрын
@@CompleteCoding 👍
@abnergrajales4225
@abnergrajales4225 3 жыл бұрын
Nice excellent!!!!!
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Glad you like it!
@indianappguy
@indianappguy 3 жыл бұрын
You are doing really great work thank you
@CompleteCoding
@CompleteCoding 3 жыл бұрын
My pleasure :)
@indianappguy
@indianappguy 3 жыл бұрын
@@CompleteCoding i am working on ses send mail its causing internal server error
@CompleteCoding
@CompleteCoding 3 жыл бұрын
There are multiple ways to debug code. You can run it locally (serverless offline), put console.logs in and see how far it gets, wrap you code in a try/catch and see the error. I've got a video on running aws locally with serverless offline
@letsgodevs
@letsgodevs 3 жыл бұрын
Thank you very much sir :)
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Most welcome!
@MagicJF
@MagicJF 2 жыл бұрын
Nice! just for testing I changed the limit from 1000 down to 5 and I got "message": "Limit Exceeded" on the 6th request :)
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Nice work! Shows that it will do what it needs to when using it for real
@alexgochenour8740
@alexgochenour8740 4 жыл бұрын
Crystal clear as always, thanks. Storing the individual users' API keys right there in the .yml file will actually work for the pet project I'm applying this to, since there's only a dozen or so users. But how do you usually store those keys for an API with a large number of users?
@CompleteCoding
@CompleteCoding 4 жыл бұрын
The next video I'm doing is on authorisers and how you can write Lambdas to validate things such as api keys. You can then store api keys in dynamo so you can easily add more customers.
@praisegodce9259
@praisegodce9259 3 жыл бұрын
@@CompleteCoding Thanks for the lessons. I will be waiting for this video.
@CodeWithEasyFaris
@CodeWithEasyFaris 3 жыл бұрын
@@CompleteCoding have u uploaded this video. i want to watch it
@CompleteCoding
@CompleteCoding 3 жыл бұрын
@@praisegodce9259 kzfaq.info/get/bejne/aL1dl8demNOZpWw.html
@CompleteCoding
@CompleteCoding 3 жыл бұрын
@@CodeWithEasyFaris kzfaq.info/get/bejne/aL1dl8demNOZpWw.html
@alanmangroo3656
@alanmangroo3656 3 жыл бұрын
Loving your videos! I want to secure my back end api so that only my front end can use it. Will an api key be visible in the browser dev tools? Is api key the right solution?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
With API keys if someone uses the app then they will be able to see the API key used (by looking at the requests in dev tools) and then use that themselves. You can pair this with CORS settings so you have a whitelist of web URLs that are able to make requests to your APIs. Even with this, if someone really wanted to then they could still access your urls but it would be a lot more effort. Making it truly secure would need something involving a login which generates a temporary access token which is needed on every request.
@DanielLpz1
@DanielLpz1 Жыл бұрын
Hello nice video, is there any way to configure an API Key into my API Gateway without an usage plan configured ?
@andresm9051
@andresm9051 3 жыл бұрын
Absolutely Awesome your videos, I got a question if I wanted renew the api keys for all user, then what I can do to distribute it without affecting backend or users experience ? every time that I deploy I get a new api key? thanks so much 🙂
@CompleteCoding
@CompleteCoding 3 жыл бұрын
If I needed to do that, I would move the API keys into a database table. I would then add a task which went through that table and updated the API key for each user. This would be triggered once the deployment completed. If you do this you may also want to do something like send the new API key to the user by SES?
@andresm9051
@andresm9051 3 жыл бұрын
@@CompleteCoding thanks for the answer, that would be a great idea as well creating a topic and publishing it a new api for any amount of time
@andresm9051
@andresm9051 3 жыл бұрын
@@CompleteCoding but now I wonder I have an user pool group which contains federated entity for unauthenticated user, what is better an api key or that federated one for only GET requests?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
@@andresm9051 That massively depends on the use case and the end user. If they're capable of dealing with tokens, refresh tokens and everything that comes with cognito then its less work for you and is a properly security tested solution. If they might be less technical then just giving them an API key might be easier.
@andresm9051
@andresm9051 3 жыл бұрын
@@CompleteCoding Thank you, I'm using cognito that will handle everything related to tokens as you mentioned then is not neeeded to use api keys only use IAM polixies to restrict access to resources
@ManikPokhetra79
@ManikPokhetra79 2 жыл бұрын
When we use this method for securing apikey and use the apikey in our headers, will the key be visible in network tags in chrome developer tools
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Yes, the api key will need to be sent as part of the headers which is viewable in dev tools.
@jacksonmangler9475
@jacksonmangler9475 Жыл бұрын
Very helpful. How would you update the serverless.yml file programmatically every time a user signs up as needed based on what was said at 12:59?
@CompleteCoding
@CompleteCoding Жыл бұрын
I wouldn't use API keys for general user access. You might use it for connecting to a system that doesn't have a more advanced login mechnaism
@Ner400
@Ner400 Жыл бұрын
Hi, I'm having issues with the private attribute, I'm getting a 403 response. Also, when I put the key, I get the 403 response, too. Can you help me please?
@CompleteCoding
@CompleteCoding Жыл бұрын
You usually get a 401 response for unauthorised requests. 403 normally means you're either hitting an endpoint that doesn't exist, or you're doing a get request to a post endpoint
@simonbennett679
@simonbennett679 8 ай бұрын
Note. This technique only applies to AWS rest API (v1)
@CompleteCoding
@CompleteCoding 6 ай бұрын
I think this video came out before http API existed :p
@simonbennett679
@simonbennett679 6 ай бұрын
My mistake!@@CompleteCoding
@vacanttime
@vacanttime 3 жыл бұрын
@complete Coding How to get the API key value in output using physical or logical ID?. because I want to export and import it in another serverless.yml file, can you help me with it?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
You can create an output from the serverless file which you can then import into another serverless project. Here's an article about creating exports www.serverless.com/blog/outputs-and-secrets
@manikandanp9751
@manikandanp9751 2 жыл бұрын
I am facing the warning unrecognized property 'apiKeys' while run the command sls deploy after added apiKeys in provider, can you please share the solution? iam using serverless version 3
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Yes, the apiKeys property has apparently moved with v3 of serverless. I've not used API Keys with v3 yet so I don't know where the right place is
@abhaysoni8631
@abhaysoni8631 2 жыл бұрын
i tried many time, but it is saying apiKeys is a invalid property, please @Complete Coding. can you verify if there is some changes. and this method is no longer supported
@CompleteCoding
@CompleteCoding 2 жыл бұрын
This video was done with Serverless Framework V2. There is a new v3 which works slightly differently
@AbrahamSalloum
@AbrahamSalloum 3 жыл бұрын
This video (and the next) no longer work as a couple of videos ago (per the comments) we had to change to httpApi (instead of http). I have been reading through the serverless docs to find a solution but they are a mess. The js ecosystem constantly makes breaking changes. Meanwhile I can run the same python code I wrote in 2008 on the latest python without issue.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
You should still be able to use http, that just creates a Rest API over a http API. This isn't related to JS at all, that is just the language I have chosen to use in these videos. The JS code still runs, it is the serverless configuration that is changing. If you'd built a Python API with Serverless, you would still have to choose between http and httpApi.
@AbrahamSalloum
@AbrahamSalloum 3 жыл бұрын
Thank you for your reply. Perhaps I did not explain clearly, or maybe there is some error in my understanding. In the video titled "Creating an API with Serverless" you mention (in reply to a commenter who has posted some updated code) that serverless v2 has introduced some breaking changes to your video. If you carry these changes forward, this video does not work with current serverless. The yaml file I start off with at the beginning of this video is already different to what you have due to this change. Here is my yaml file: gist.github.com/AbrahamSalloum/5cd3ebb6a571eb056b7031b85625619a. The error is related to an unknow keyword (I cant remember exactly, will redo later and see) Thanks for the video series.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
@@AbrahamSalloum I think that I was wrong in that original comment. Using an event type of "http" still works (I just checked). Also the difference between http and httpApi should be minimal
@AbrahamSalloum
@AbrahamSalloum 3 жыл бұрын
@@CompleteCoding Thanks. I originally changed from 'http' to 'httpApi' because I was getting an 'internal server error' but I now think it was because the status/statusCode keyword changed in API_Responses.js. statusCode works for http, and status works for httpApi, so I went down the wrong rabbit hole. Incidentally, when I try to use httpApi, I get the warning: "at 'functions.getUser.events[0].httpApi': unrecognized property 'private'" I think it wants me to set up tokens instead. Thanks for your help.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
@@AbrahamSalloum Great that you found a solution and figured out that response code differences :)
How to Proxy API requests to your legacy endpoints with Serverless
10:08
Complete Coding - Master AWS Serverless
Рет қаралды 3,7 М.
Creating an API with Serverless - API Gateway and AWS Lambda
14:23
Complete Coding - Master AWS Serverless
Рет қаралды 30 М.
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 28 МЛН
Пранк пошел не по плану…🥲
00:59
Саша Квашеная
Рет қаралды 7 МЛН
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 9 МЛН
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН
How the Heck Do API Keys Work?
39:43
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 44 М.
Create a Serverless Database - DynamoDB with the Serverless Framework
9:59
Complete Coding - Master AWS Serverless
Рет қаралды 18 М.
Create an API to get data from your DynamoDB Database
20:17
Complete Coding - Master AWS Serverless
Рет қаралды 22 М.
How to ACTUALLY Secure Your API (5 Steps)
7:42
Josh tried coding
Рет қаралды 58 М.
How to send an email with Amazon SES and Serverless - tutorial
20:02
Complete Coding - Master AWS Serverless
Рет қаралды 26 М.
Secure API Gateway using Lambda Authorizer (NEW)
33:32
LoveToCode
Рет қаралды 22 М.
Serverless Offline for testing on your local machine. Tutorial with DynamoDB
18:16
Complete Coding - Master AWS Serverless
Рет қаралды 35 М.
Stop, Intel’s Already Dead! - AMD Ryzen 9600X & 9700X Review
13:47
Linus Tech Tips
Рет қаралды 1 МЛН
Why didn't the Angular team just use RxJS instead of Signals?
8:15
Joshua Morony
Рет қаралды 91 М.
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 28 МЛН