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

Created on 13 Aug 2020  路  2Comments  路  Source: aws-amplify/amplify-cli

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
analytics bug notifications

Most helpful comment

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.

All 2 comments

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?

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.

Was this page helpful?
0 / 5 - 0 ratings