Parsing of Identity Pool Roles fails when role arn contains multiple '/' characters
How did you install the Amplify CLI?
yarn build from v12.1.0 tag
If applicable, what version of Node.js are you using?
18.15.0
Amplify CLI Version
12.0.3 (v12.1.0 tag)
What operating system are you using?
Mac M2
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made
Describe the bug
I attempted and failed to run amplify import auth to import Cognito User Pool and Identity Pool settings from my AWS account.
When creating a Cognito Identity Pool, the v2 console guides you through creating Unauthenticated and Authenticated roles.
When creating the roles, the console will prepend service-role/ to whatever IAM role name you specify.
For example, in this UI I am entering my-role:
And the subsequent role arn will be created as:
arn:aws:iam::<account-id>:role/service-role/my-role
I believe this probably differs from the original console UI which might not prepend service-role/ to the arn.
When running amplify import auth the following code attempts to split the Identity Pool's Role arns into two parts and select the last part as the 'resourceName':
https://github.com/aws-amplify/amplify-cli/blob/bc5957a4d5fd2c036fde75d4da657ba733c83a22/packages/amplify-provider-awscloudformation/src/aws-utils/IdentityPoolService.ts#L107
When it attempts to parse arn:aws:iam::<account-id>:role/service-role/my-role it fails with an exception Cannot parse arn: 'arn:aws:iam::<account-id>:role/service-role/my-role'. due to there being more than two parts.
Expected behavior
I expect amplify import auth to be compatible with the default Cognito Identity Pool console's created role resource names.
Reproduction steps
- Create a Cognito Identity Pool with reasonable defaults specified for Authenticated and Unauthenticated roles using the latest console version & ensuring that the role arn's are prepended with
service-role/ - Run
amplify import auth - Receive exception
Cannot parse arn: <arn>
Project Identifier
No response
Log output
No response
Additional information
Simply changing the amplify code to use the last part of a multi-part arn allows the amplify import auth command to succeed but subsequently breaks builds (as the build pipeline will use the official amplify-cli version with the bug in it).
Before submitting, please confirm:
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
Hey @geoff-mwi, 👋 thank you for reaching out. But I was able to reproduce the issue by creating a identity pool using the new console that automatically appended the service role to unauth and auth role names. for example: arn:aws:iam::<account-id>:role/service-role/import-auth-role-test
observed the following error
🛑 Cannot parse arn: 'arn:aws:iam::<account-id>:role/service-role/import-auth-role-test'.
Marking as bug
Hi, do you know if this also causes an error with the Amplify Swift SDK: "Invalid identity pool configuration. Check assigned IAM roles for this pool?" I don't know why it would but I'm also having this issue with being unable to parse the arn so I can't reimport my auth to verify whether it's a problem with my configuration or with my actual IAM role.
Any further insights on this issue?
A fix for this issue was released in version 12.2.2. Please comment below if you experience any further difficulties importing auth after upgrading.
⚠️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.
@jhockett
I still get errors when trying to push changes 🛑 Resource is not in the state stackUpdateComplete Name: AuthRolePolicy01921FC820 (AWS::IAM::ManagedPolicy), Event Type: create, Reason: The specified value for roleName is invalid. It must contain only alphanumeric characters and/or the following: +=,.@_- (Service: AmazonIdentityManagement; Status Code: 400; Error Code: ValidationError; Requ
can we revert back to V1 of amplify console??