Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS - API keys available on the Serverless Offline framework?

I use Serverless Offline to develop a Web project.

I need of API Keys to access to resource on Serverless AWS Lamda.

I have a serverless.yml with my service and my provider.

In Postman, I access to my route (http://127.0.0.1:3333/segments/UUID/test), and I haven't any error (as Forbidden message), the Lambda is executed...

test:
  handler: src/Api/segment.test
  events:
    - http:
        path: segments/{segmentUuid}/test
        method: post
        request:
          parameters:
            paths:
              segmentUuid: true
        private: true

The route in question is not protected by private.

like image 956
pirmax Avatar asked Feb 19 '18 15:02

pirmax


1 Answers

https://www.npmjs.com/package/serverless-offline#token-authorizers

Serverless-offline will emulate the behaviour of APIG and create a random token that's printed on the screen. With this token you can access your private methods adding x-api-key: generatedToken to your request header. All api keys will share the same token. To specify a custom token use the --apiKey cli option.

Command will look like this:

sls offline --apiKey any-pregenerated-key
like image 107
Yurii Avatar answered Oct 09 '22 19:10

Yurii