amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Duplicate Pinpoint projects created when creating new Amplify environment (breaks push notifications)

Open mdoesburg opened this issue 5 years ago • 11 comments

Describe the bug I have a project which uses push notifications. Upon creating a new environment by following the steps outlined here, the Amplify CLI prompts the user for APNS and FCM credentials prior to pushing. After supplying the credentials, the Pinpoint project gets created on AWS. This all happens before pushing the project to the cloud. After successfully going through all the amplify env add steps, and finishing with amplify push, the Amplify CLI creates another Pinpoint project, resulting in 2 Pinpoint projects.

I compared the amplify-meta.json files from my initial env (dev) and my new env (test), and noticed that the new (test) environment has a different output.Id under analytics than the output.Id under notifications. The initial env has the same output IDs for these categories.

This is problematic, because I have 2 Lambda functions which send out push notifications. They both have all the permissions for the 'analytics' category. Whenever one of these functions attempts to send a push notification in the test env, it fails because the function has the wrong Pinpoint ID.

Amplify CLI Version @aws-amplify/[email protected]

To Reproduce

  1. Create an Amplify project
  2. Add push notifications
  3. Create a new environment
  4. Witness duplicate Pinpoint project

Expected behavior I expect only one Pinpoint project to be created, and my new enviroment to match my original environment.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Node Version. v14.4.0

mdoesburg avatar Aug 13 '20 19:08 mdoesburg

The Amplify docs suggest that you need to setup the Analytics category before adding the Notifications category:

Push Notifications category is integrated with AWS Amplify Analytics category to be able to track notifications. Make sure that you have configured the Analytics category in your app before configuring the Push Notifications category.

This Medium post suggest you shouldn't:

Note: Do NOT also run amplify add analytics because amplify add notifications already initializes an AWS Pinpoint project, called AmplifyAndroidPushXXXXX-env

I did run amplify analytics add prior to running amplify notifications add in my initial environment, and ended up with only one Pinpoint project, which is shared by the Analytics category and Notifications category, but in my new env I end up with 2 Pinpoint projects.

Could this be related or the cause of this issue?

I know running amplify analytics add prior to amplify notifications add is a requirement, since you cannot add permissions to a function with just the notifications category. Attempting to add notifications permissions to a Lambda function results in the following message:

Policies cannot be added for notifications/resource-name

The only way for a Lambda function to send push notifications is to add permissions for the analytics category, but with that being said, I feel like the core issue lies with adding these 2 categories, since a new environment doesn't seem to understand these should share the same Pinpoint project?

mdoesburg avatar Aug 13 '20 20:08 mdoesburg

For anyone else facing this issue, the workaround for now is:

  1. Remove Lambda function Analytics category dependencies/permissions
  2. Remove Analytics category
  3. Remove Notifications category
  4. Push changes
  5. Add Analytics category
  6. Push changes
  7. Add Notifications category
  8. Add Lambda function Analytics category dependencies/permissions

After basically removing and re-adding the Analytics and Notifications categories, your new environment will only end up with one shared Pinpoint project.

mdoesburg avatar Aug 13 '20 20:08 mdoesburg

Any decent solution yet?

avlonder avatar Jul 27 '21 14:07 avlonder

I've spent most of the day debugging this issue.

Adding of notifications needs to happen first, When you then add analytics, the pinpoint provider detects that notifications exist and it writes the appId to the parameters.json The cloudformation doesn't create a new pinpoint instance if an appId is passed.

The problem though is that this will then fail when creating a new environment or switching between envronments.

When creating a new environment the first thing it does before the push is setup notifications and therefore creates a pinpoint instance.

If you then perform the push, because the AppId is saved in parameters.json it doesn't create a duplicate but now the aws-exports will reference an instance from a different stage that doesn't exist.

Perhaps doing something similar to functions where environment variables are injected into the parameters could be a fix?

johnf avatar Dec 07 '21 05:12 johnf

Current workaround when adding a new environment

  • amplify env add NAME - to create the new environment
  • Find the appid in team-provider.json for pinpoint
  • Update amplify/backend/analytics/NAME/parameter.skon and set AppId
  • amplify push

johnf avatar Dec 07 '21 06:12 johnf

Seems to be still a problem.

Separate pinpoint created for notifications / analytics.

Deleted one thinking it wasn't in use, now we got a whole bunch of problems 😅

dylan-westbury avatar Feb 04 '22 01:02 dylan-westbury

It just happened to us using amplify cli version 7.6.23.

michaetto avatar Mar 16 '22 09:03 michaetto

Still happening to us as well, except when using the recommended fix to hardcode the appId in the parameters amplify ends up deleting the original Pinpoint Application. The only way for Amplify to create a new Pinpoint application is to remove the appId and have it blank.

Pickleboyonline avatar Mar 24 '22 22:03 Pickleboyonline

asked for the .p12 again and again... some error here.

biller-aivy avatar Apr 22 '22 12:04 biller-aivy

Since the previous workaround no longer seems to work, this may help some of you facing this issue. This is what worked for me as of version 9.1.0 of the CLI.

1. amplify env add <YOUR_ENV>
    - Follow the prompts to setup notifications
3. amplify remove notifications
    - Choose what to remove. The Pinpoint application
    - Confirm that you want to delete the associated Amazon Pinpoint application Yes
4. amplify status
    - Notifications should no longer be showing, while Auth and Analytics should be in Create
5.  amplify push
    - Are you sure you want to continue? Yes
6. amplify add notifications
    - Follow prompts to setup notifications again

At the end of this I only had one pinpoint project that was setup as I expected it to be. Hope it helps

bgneu avatar Aug 02 '22 20:08 bgneu

This is still a problem, even on the latest Amplify CLI.
Makes CI/CD with fresh backend environments really frustrating when anything that depends on Pinpoint starts failing. For me, this breaks anything that touches Pinpoint, (Push,SMS, Analytics etc)

Duder-onomy avatar Sep 07 '22 00:09 Duder-onomy

I believe I just ran into this as well. I'm not sure why since I've had a dev and test environment for months and the CI/CD has been working great. But what I didn't realize is that notifications weren't working on the test side (testers glossed over it). I now need to add the project ID in my code to send notifications in the test environment but of course I have two (actually three for some reason all with the same creation date back in March of this year).

Regardless of getting notifications working on our TEST environment I ran into the CI/CD issue where it hangs and then eventually times out after 30 minutes. In the amplify build logs it gets stuck at :

2022-10-06T17:36:49.610Z [WARNING]: - Building resource auth/[REDACTED]

Not much to go on but between this ticket and https://github.com/aws-amplify/amplify-hosting/issues/2541 listed above I'm drilling down into this pinpoint issue. I'll try the solution @bgneu has suggested on our test environment and see what happens.

Etep15 avatar Oct 06 '22 18:10 Etep15

We are facing the same issue as @Etep15, where our production environment won't deploy with amplify hosting when building react frontend.

It gets stuck on this 2022-10-20T01:37:57.831Z [WARNING]: - Building resource auth/userPoolGroups

After 30 minutes the build times out.

We were able to push the production environment backend with amplify push from local computer, but now we can't deploy the frontend.

We also tried to skip the push within amplify hosting following the documentation here https://docs.aws.amazon.com/amplify/latest/userguide/amplify-config-autogeneration.html

However it still gets stuck:

2022-10-20T02:29:57.710Z [INFO]: ## Running amplify pull to generate aws-exports.js file for frontend
2022-10-20T02:30:01.399Z [INFO]: [0mAmplify AppID found: d3tyae2uog3myc. Amplify App name is: XXXXXXXXX[0m
2022-10-20T02:30:01.464Z [INFO]: [0mBackend environment prod found in Amplify Console app: Swysh Backoffice[0m
2022-10-20T02:30:06.000Z [WARNING]: - Fetching updates to backend environment: prod from the cloud.
2022-10-20T02:30:09.397Z [WARNING]: - Building resource auth/userPoolGroups

dylan-westbury avatar Oct 20 '22 01:10 dylan-westbury

Hi @mdoesburg the issue with duplicate pinpoint projects should be fixed in latest Amplify CLI

pavellazar avatar Feb 24 '23 21:02 pavellazar

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Feb 24 '23 21:02 github-actions[bot]