Skip to content

Enable API Gateway authorizers #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 30, 2018

Conversation

vlewin
Copy link
Contributor

@vlewin vlewin commented Jul 14, 2018

@vlewin
Copy link
Contributor Author

vlewin commented Jul 14, 2018

This PR is based on #131

@vlewin
Copy link
Contributor Author

vlewin commented Jul 14, 2018

@horike37 Hello Takahiro, is there a reason why not to use a serverless internal libraries instead of copying files from serverless source?

@horike37 horike37 added this to the 1.6 milestone Jul 17, 2018
@horike37
Copy link
Collaborator

Hey @vlewin !
Thank you for implementing this feature! Really looking forward to seeing this will be live as well as #131!!
Let me know if you will be ready for review 😄

is there a reason why not to use a serverless internal libraries instead of copying files from serverless source?

Good point 👍
sls internal libraries around events have not been considered as libraries which referenced from external plugins.
Of course, I understanding the best way that using those in terms of keeping codebase clean. However, If I use it, this plugin might be broken when releasing the serverless framework new version.

That being said, I have decided to get copying way for keeping it safe.

@vlewin
Copy link
Contributor Author

vlewin commented Jul 17, 2018

@horike37 Thank you for quick response. Maybe we can pin tested and supported version of serverless in package.json and update it once a new version is released. So we can test your plugin and if all green release it. As you can see from my PR serverless is under active development and this results in a lot of changes per minor version. I already tested your plugin with the libraries from lastest serverless version and did't detected any issues.

Copy link
Collaborator

@horike37 horike37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vlewin, thank you for the effort and implementing awesome features 👍 💯
Looks great and can't wait the next release!!

I just reviewed this PR, it seems that this PR include the following features not just authorizer.

  • maxAge for cors
  • endpointType configuration
  • share API
  • resourcePolicy configuration

You might want to separate PR for each feature, otherwise, I can't review and test properly with narrow ing it down. The main point of this PR should authorizer feature.

Also, Please add the explanation of those to README so that Let users knows those awesome features!

Thanks in advance!

CHANGELOG.md Outdated
@@ -1,6 +1,10 @@
# 1.5.1(10.07.2018)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you delete it once?
This should be added while releasing a new version.

@@ -24,6 +25,16 @@ module.exports = {
'Access-Control-Allow-Credentials': `'${config.allowCredentials}'`,
};

// Enable CORS Max Age usage if set
if (_.has(config, 'maxAge')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxAge feature is great!
However, does this need for authorizer?
If not, would be great if you can separate maxAge PR from this one.

@@ -6,65 +6,247 @@ const _ = require('lodash');
module.exports = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those changes of this file for share API feature?
If so, could you remove those from this PR?

@@ -70,15 +70,15 @@ describe('#compileResources()', () => {
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. maybe those are for share API.

let endpointType = 'EDGE';

if (this.serverless.service.provider.endpointType) {
const validEndpointTypes = ['REGIONAL', 'EDGE', 'PRIVATE'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting endpointType is great!
However, those are not for authorizer feature.
Could you separate PR for each feature?

},
},
});

if (!_.isEmpty(this.serverless.service.provider.resourcePolicy)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. this is resourcePolicy feature.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "serverless-step-functions",
"version": "1.5.0",
"version": "1.6.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you turn back to 1.5.0?
This should be updated while releasing a new version.

@vlewin
Copy link
Contributor Author

vlewin commented Jul 21, 2018

Hi @horike37 thank you for review! You are right this PR includes changes from #131. Please review #131 Shared API Gateway pull request first.

Once this #131 is merged to master we will see only the changes for authorizers. If you want to add authorizers support first I can open a separate pull request but our team need both changes in the next version. Otherwise we have to use my fork what I want to avoid.

I'm sorry for the confusion.

@horike37
Copy link
Collaborator

Hi @vlewin
Could you rebase this branch from the top of master so that we can see only the changes of authorizer feature? #131 was just merged

@vlewin vlewin force-pushed the add_authorizer_support branch from 7235233 to 358e205 Compare July 25, 2018 19:31
@vlewin
Copy link
Contributor Author

vlewin commented Jul 25, 2018

@horike37 JFYI: branch is rebased, now we should see authorizer related changes only

@vlewin
Copy link
Contributor Author

vlewin commented Jul 25, 2018

Copy link
Collaborator

@horike37 horike37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlewin

Should we start using serverless internal libraries?

Either's fine. If using those, we should move Serverless to dependencies from devDependencies.
Could you add documentation to README as well?

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "serverless-step-functions",
"version": "1.5.1",
"version": "1.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert it

@horike37
Copy link
Collaborator

Hi @vlewin, thank you for fixing!
I tested locally but does not work with the following error.

$ sls deploy -v
Serverless: Packaging service...
Serverless: Excluding development dependencies...
 
  Type Error ---------------------------------------------
 
  Cannot read property 'replace' of undefined
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.4.0
     Serverless Version:     1.29.1

Here is my serverless.yml file.

service: step-func

provider:
  name: aws
  runtime: nodejs6.10

functions:
  hello:
    handler: handler.hello
  authorizerFunc:
    handler: authorizer.js

stepFunctions:
  stateMachines:
    step-func:
      events:
        - http:
            path: gofunction
            method: GET
            authorizer: authorizerFunc
      name: my-${opt:stage}-statemachine
      definition:
        StartAt: Ingest
        States:
          Ingest:
            Type: Task
            Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-hello
            End: true


plugins:
  - serverless-pseudo-parameters
  - serverless-step-functions

Any ideas why?

@vlewin
Copy link
Contributor Author

vlewin commented Jul 29, 2018

@horike37 Thank you very much for testing. I extended authorizer support, previously it was only possible with Shared authorizers now it should work with any authorizer type e.g. AWS_AIM, Congnito or custom.

Here is my serverless.yml:

service: sfn-api-gateway-playground

provider:
  name: aws
  runtime: nodejs8.10
  region: eu-central-1

  apiGateway: # Optional API Gateway global config
    restApiId: n42gvt3whk # REST API resource ID. Default is generated by the framework
    restApiRootResourceId: 9f8qmgn5d6 # Root resource ID, represent as / path
    restApiResources: # List of existing resources that were created in the REST API. This is required or the stack will be conflicted
      '/playground': skvi34

functions:
  customAuthorizer:
      handler: authorizer.handler

stepFunctions:
  stateMachines:
    SfnApiGateway:
      events:
        - http:
            path: /playground/step
            method: GET
            authorizer: customAuthorizer
            # authorizer:
            #   type: CUSTOM
            #   authorizerId: 43mrom
            cors:
              origin: '*'
              maxAge: 86400
      definition:
        Comment: "A sample application"
        StartAt: Start
        States:
          Start:
            Type: Pass
            End: true
plugins:
  - serverless-step-functions
  - serverless-pseudo-parameters

@horike37 horike37 merged commit be46b6d into serverless-operations:master Jul 30, 2018
@horike37
Copy link
Collaborator

@vlewin
Thank you for the update!
LGTM 👍 💯 I will release a new version soon!
Awesome work!!!!

@vlewin
Copy link
Contributor Author

vlewin commented Jul 30, 2018

@horike37 Awesome! Thank you very much for review!

ss-betseqnzr pushed a commit to BetSEQNZR/serverless-step-functions that referenced this pull request Sep 8, 2023
…er_support

Enable API Gateway authorizers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants