Skip to content
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

Trigger changed to initial default after every deployment #9229

Closed
3 tasks done
kevinRR opened this issue Nov 17, 2021 · 8 comments
Closed
3 tasks done

Trigger changed to initial default after every deployment #9229

kevinRR opened this issue Nov 17, 2021 · 8 comments
Assignees
Labels
auth Issues tied to the auth category of the CLI bug Something isn't working duplicate If marked with duplicate, issue will be closed & original will be added for traceability transferred This issue was transferred from another Amplify project

Comments

@kevinRR
Copy link

kevinRR commented Nov 17, 2021

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Not applicable

Amplify Categories

hosting

Environment information

suppose I have two triggers CustomMessage and PostConfirmation if I deployed my any branch its changes to none


Describe the bug

If I set the Lamda function trigger its change to none after every deployment

Expected behavior

should not change the Lamda function to none by default

Reproduction steps

  1. let say I set the Lamda function to suppose 'PostConfirmationDev"
  2. Then I make deployment to dev server
  3. My lambda function changed to none from the dropdwon
    Screen Shot 2021-11-17 at 17 55 57
    Screen Shot 2021-11-17 at 17 56 10

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@chrisbonifacio chrisbonifacio self-assigned this Nov 17, 2021
@chrisbonifacio
Copy link

chrisbonifacio commented Nov 17, 2021

Hi @kevinRR this is more of a CLI issue but I believe this is the expected behavior. If you change resources in the console, your local project won't know about it and the next time you run amplify push it will override any changes you might've made with the local configuration.

So, I think the only way to avoid this is to setup the trigger through the CLI by running amplify update auth and selecting Walkthrough all the auth configurations. Eventually it will ask if you want to setup Lambda Triggers for Cognito.

Screen Shot 2021-11-17 at 2 10 34 PM

@cespin
Copy link

cespin commented Nov 22, 2021

@chrisbonifacio , I'm having the exact same issue in multiple projects. In one of these projects it's always the same Cognito trigger that appears blank all the time. In the other one it's all of them.

I've tried multiple combinations of amplify update auth with the Walkthrough all the auth configurations option like you recommended. I've even tried removing the Cognito triggers, doing and amplify push and creating them again.

The cli-inputs.json seems consistent and complete with my answers. It references all the triggers but the effective CloudFormation is missing them.

I'm trying right now to override them using the new override functionality but there's definitely a bug somewhere.

@cespin
Copy link

cespin commented Nov 22, 2021

@kevinRR , I fixed this with:

My override.ts looks like this:

import { AmplifyAuthCognitoStackTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyAuthCognitoStackTemplate) {
    // START - Lambda Triggers
    // This is being done because the generated stack is missing Cognito triggers - Don't know why
    const newLambdaConfig = {
        ...resources.userPool.lambdaConfig,
    };

    if (!newLambdaConfig["preSignUp"]) {
        newLambdaConfig["preSignUp"] = {
            "Ref": "functionomyprojectauthPreSignupArn"
        };
    }

    resources.userPool.lambdaConfig = newLambdaConfig
    // END - Lambda Triggers
}

At this point what's missing is a resource policy for the Pre Signup Lambda. I put that in the custom stack, the resource looks like this:

    "UserPreSignupLambdaInvokePermission": {
      "Type": "AWS::Lambda::Permission",
      "Properties": {
        "Action": "lambda:invokeFunction",
        "FunctionName": {
          "Ref": "functionmyprojectauthPreSignupName"
        },
        "Principal": "cognito-idp.amazonaws.com",
        "SourceArn": {
          "Ref": "authmyprojectUserPoolArn"
        }
      }
    }

You could optionally do that last step in the Lambda's CloudFormation file.

@chrisbonifacio
Copy link

Hey @cespin 👋 thank you for providing a workaround. Just confirmed that this is a known bug #8997 so I will transfer this over to the CLI repo to be investigated further.

@chrisbonifacio chrisbonifacio transferred this issue from aws-amplify/amplify-js Dec 6, 2021
@chrisbonifacio chrisbonifacio added duplicate If marked with duplicate, issue will be closed & original will be added for traceability transferred This issue was transferred from another Amplify project labels Dec 6, 2021
@josefaidt
Copy link
Contributor

Hey @kevinRR and @cespin 👋 thanks for raising this! As @chrisbonifacio mentioned this is a duplicate of #8997 and we'll close in favor of tracking the existing item. Please subscribe to the existing issue for further updates. 🙂

As a side note, love to see how the overrides were used as a workaround!

@josefaidt josefaidt added auth Issues tied to the auth category of the CLI bug Something isn't working labels Dec 6, 2021
@hackrx
Copy link

hackrx commented Dec 6, 2021

Hey @cespin, I tried your solution, but it is not working for me.
Error:

UPDATE_FAILED      authBlog8xxx3239                     AWS::CloudFormation::Stack Tue Dec 07 2021 02:45:34 GMT+0530 (India Standard Time) Template format error: Unresolved resource dependencies [Blog8xxx3239PreSignup-testapis, Blog8xxx3239PostConfirmation-testapis] in the Resources block of the template

And my override.ts file:

import { AmplifyAuthCognitoStackTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyAuthCognitoStackTemplate) {
  const newLambdaConfig = {
    ...resources.userPool.lambdaConfig,
};

if (!newLambdaConfig["preSignUp"]) {
    newLambdaConfig["preSignUp"] = {
        "Ref": "Blog8xxx3239PreSignup-testapis"
    };
    newLambdaConfig["postConfirmation"] = {
      "Ref": "Blog8xxx3239PostConfirmation-testapis"
    };
}

resources.userPool.lambdaConfig = newLambdaConfig;
}

What I have also tried:

  1. in Ref: Value -> Blog8xxx3239PreSignup , but didn't worked.
  2. in Ref: Value -> Blog8xxx3239PreSignup-testapisArn , but didn't worked.
  3. in Ref: Value -> arn:aws:lambda:us-east-2:xxxxx65:function:PreSignup-testapis, but didn't worked. [Copied arn from IAM console.]
    In 3rd case, I am not getting any error, but it is also not updating the cognito console.
    Please correct me, if I am missing something.

@cespin
Copy link

cespin commented Dec 9, 2021

Hi @hackrx ,

Are those stack params ? Check the effective CloudFormation file that's being generated by Amplify and the available stack parameters. If the parameter is available you should then be able to Ref it.

In my case all the lambda triggers were already there as params so I didn't have to add them.

If you need to add params you can leverage Amplify env vars option or you can declare a stack dependency. I declare stack dependencies by manually modifying the team-provider-info.json file and then doing a amplify env checkout NAME command. All dependencies will be available as stack parameters.

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auth Issues tied to the auth category of the CLI bug Something isn't working duplicate If marked with duplicate, issue will be closed & original will be added for traceability transferred This issue was transferred from another Amplify project
Projects
None yet
Development

No branches or pull requests

5 participants