Securing Your Serverless API With API Keys

แชร์
ฝัง

ความคิดเห็น • 76

  • @toninotonnato7776
    @toninotonnato7776 2 ปีที่แล้ว

    Excellent tutorial, clear step by step guide. I wish there were more like this around. Thanks! :)

  • @muralielumalai
    @muralielumalai 3 ปีที่แล้ว

    your explanations are awesome.!

  • @pavithrab2884
    @pavithrab2884 ปีที่แล้ว

    Hey Sam, you are awesome and definitely a savior for me .Kudos

  • @abdelhadidjafer7004
    @abdelhadidjafer7004 2 ปีที่แล้ว +5

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +3

      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 ปีที่แล้ว +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:)

  • @uthpalapitawela7054
    @uthpalapitawela7054 3 ปีที่แล้ว

    Thank you very much. Great video

  • @programmusicuk
    @programmusicuk 4 ปีที่แล้ว +2

    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.

  • @prajwalhalwai1042
    @prajwalhalwai1042 3 ปีที่แล้ว

    Great work and videos!

  • @nielsrozeboom8852
    @nielsrozeboom8852 3 ปีที่แล้ว +1

    great tutorials! You deserve a lot of likes! :-)

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      Thanks Niels! Glad you liked the video

  • @neosarchizo
    @neosarchizo 4 ปีที่แล้ว

    Thanks for the good video again!

    • @CompleteCoding
      @CompleteCoding  4 ปีที่แล้ว +1

      Always happy when someone enjoys a video

  • @shadmanmartinpiyal4057
    @shadmanmartinpiyal4057 3 ปีที่แล้ว

    Super excellent!

  • @marynavatsko9692
    @marynavatsko9692 3 ปีที่แล้ว +2

    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 ปีที่แล้ว +4

      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 👍

  • @indianappguy
    @indianappguy 3 ปีที่แล้ว

    You are doing really great work thank you

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      My pleasure :)

    • @indianappguy
      @indianappguy 3 ปีที่แล้ว +1

      @@CompleteCoding i am working on ses send mail its causing internal server error

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว +1

      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

  • @sergiosepulveda7860
    @sergiosepulveda7860 10 หลายเดือนก่อน

    thanks a lot

  • @letsgodevs
    @letsgodevs 3 ปีที่แล้ว

    Thank you very much sir :)

  • @abnergrajales4225
    @abnergrajales4225 3 ปีที่แล้ว

    Nice excellent!!!!!

  • @simonbennett679
    @simonbennett679 7 หลายเดือนก่อน +1

    Note. This technique only applies to AWS rest API (v1)

    • @CompleteCoding
      @CompleteCoding  5 หลายเดือนก่อน +1

      I think this video came out before http API existed :p

    • @simonbennett679
      @simonbennett679 5 หลายเดือนก่อน

      My mistake!@@CompleteCoding

  • @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 ปีที่แล้ว +1

      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 th-cam.com/video/2W-dd-3m5u8/w-d-xo.html

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      @@CodeWithEasyFaris th-cam.com/video/2W-dd-3m5u8/w-d-xo.html

  • @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

  • @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 ปีที่แล้ว +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.

  • @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

  • @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

  • @DanielLpz1
    @DanielLpz1 ปีที่แล้ว

    Hello nice video, is there any way to configure an API Key into my API Gateway without an usage plan configured ?

  • @vacanttime
    @vacanttime 3 ปีที่แล้ว +1

    @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 ปีที่แล้ว +1

      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 :)