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

Introduce a functionality which attach events to an existing resource #4241

Open
horike37 opened this Issue Sep 10, 2017 · 7 comments

Comments

Projects
None yet
5 participants
@horike37
Member

horike37 commented Sep 10, 2017

This is a Feature Proposal

Description

For feature proposals:

  • What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us.

    S3 and cognitoUserPool events can't attach an existing resource. I think the main reason is that those can't specify an external resource within CF generated by Serverless.

However, I think many users hope that.
I think there are many cases that data sources like S3, DynamoDB or Cognito userpool are preferred to separate a stack from a one which includes Lambda.
If those are built in a same service, you can't remove and recreate anytime since data sources have a state.

  • If there is additional config how would it look

Similar or dependent issues:

@a-suenami

This comment has been minimized.

a-suenami commented Dec 7, 2017

I have the same idea. I want this feature.
What status is it?

@horike37

This comment has been minimized.

Member

horike37 commented Dec 7, 2017

Thank you for pinging @a-suenami 👍
To implement this feature, we need to decide how to parse CloudFormation template(in generally speaking, the Serverless Framework convert serverless.yml setting to CF template.), because it would break the consistency of deployment if we choose a way without CF.

However, TBH, I don't have the best way.
Do you have any ideas?
cc: @serverless/framework-maintainers

@a-suenami

This comment has been minimized.

a-suenami commented Dec 7, 2017

Ah, I see...
I'm sorry but I have no ideas because I'm not familiar with CloudFormation. 🙇
So I'll see the current implementation and consider how to realize it.

@HyperBrain

This comment has been minimized.

Member

HyperBrain commented Dec 7, 2017

I'm quite sure that this is possible with a proper ${cf:...} variable reference. You can address any output variable from the other stack. So the only thing you have to make sure is, to have the other stack export the arn of the target correctly.

You also can use the cf variable references within your resources part of the serverless.yml and define the trigger by yourself.

However, we have to check if the current implementation of the S3 and User Pool events handle the subscriptions, in case one would just specify an arn instead of something else. This has nothing to do with Serverless' generated CF template, but more the internal creation and handling of the events.

@a-suenami

This comment has been minimized.

a-suenami commented Dec 8, 2017

@HyperBrain Thank you for your answer, but I can't clearly know what you mean.

For example, my serverless.yml is here.

functions:
  cognito-user-pool-custom-message-trigger:
    handler: index.handler
    events:
      - cognitoUserPool:
          pool: MyPool
          trigger: CustomMessage

Then, generated .serverless/cloudformation-template-update-stack.json is as blow.

"CognitoUserPoolMyPool": {
  "Type": "AWS::Cognito::UserPool",
  "Properties": {
    "UserPoolName": "MyPool",
    "LambdaConfig": {
      "CustomMessage": {
        "Fn::GetAtt": [
          "CognitoDashuserDashpoolDashcustomDashmessageDashtriggerLambdaFunction",
          "Arn"
        ]
      }
    }
  },
  "DependsOn": [
    "CognitoDashuserDashpoolDashcustomDashmessageDashtriggerLambdaFunction"
  ]
},

Because of DependsOn attribute, each lambda functions are created first, and Cognito User Pool is created next. Is it right?

I want to:

  1. create a resource of Cognito User Pool in some way (AWS Console, another CF stack, terraform, and so on)
  2. attach the Lambda Functions (defined by serverless framework) to the created User Pool

Can I do that? If yes, how can I do?

@a-suenami

This comment has been minimized.

a-suenami commented Dec 8, 2017

I want to ONLY attach triggers to existing User Pool, don't want to create new User Pool by Serverless framework.

@ldgarcia

This comment has been minimized.

Contributor

ldgarcia commented Mar 27, 2018

Any update on this issue?

Currently, I have to manually configure the triggers in the Cognito console.

I've tried this, but it doesn't work:

functions:
  postConfirmation:
    handler: functions/accounts/postConfirmation.handler
    events:
      - cognitoUserPool:
        pool: ${self:custom.extra.cognito.userPoolArn}
        trigger: PostConfirmation

I cannot use CloudFormation to create the user pool yet, because it is not feature complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment