Home > front end >  How to Add REST API to Amplify v2 Android App?
How to Add REST API to Amplify v2 Android App?

Time:02-02

I cannot push my Amplify backend after performing amplify add api for REST APIs. I get the following IAM error in the CLI during the "Creating API models..." stage:

User: arn:aws:iam::xxxxxxxxxxxx:user/tb2-amplify is not authorized to perform: apigateway:GET on resource: arn:aws:apigateway:us-east-1::/restapis/xxxxxxxxxx/stages/dev/sdks/android because no identity-based policy allows the apigateway:GET action

All I need is a public GET method to read an item from a DynamoDB table. My desired pipeline is android -> Amplify.API.get() -> Lambda Function -> DynamoDB. I have followed every guide available in the Amplify Docs (Libraries/Guides), re-initialized Amplify in the project with API being the only resource, tried to manually add API to the amplifyconfiguration.json file. I am stumped.

Is my desired pipeline the problem? Is there configuring I need to perform before amplify push? Does anyone know why my configured IAM is not authorized to do this, even though the permission has been granted?

UPDATE

Granting my IAM user full administrator access allows me to amplify push the backend. I am now getting build errors like:

package com.amazonaws.mobileconnectors.apigateway.annotation does not exist

package com.amazonaws.mobileconnectors.apigateway does not exist

These errors appear 6 times in a generated package called tb2api.TbapiClient.Java

Looking into this now. (looked, just needed to add implementation 'com.amazonaws:aws-android-sdk-apigateway-core:<version>' to gradle.

CodePudding user response:

It appears that the user that the amplify build is using does not have permission for apigateway:GET.

Head over to the tb2-amplify user in IAM and look at the "Permissions policies". You should have a Policy name AdministratorAccess-Amplify of type AWS managed. That policy as most of the permissions you need for Amplify projects.

If the user doesn't have that policy, add it, or add the individual permissions needed as you encounter them.

This policy should get you to your next error:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": 
            [
              "apigateway:DELETE",
              "apigateway:GET",
              "apigateway:PATCH",
              "apigateway:POST",
              "apigateway:PUT"
            ],
            "Resource": "*"
        }
    ]
}

EDIT Another Amplify user reported an issue that seems the same or extremely similar to what you're experiencing. Try giving your tb2-amplify user full permissions and see if that clears up the issue. If it does, you've narrowed this down. Remove the 'full permissions' after deploying and add to the bug description.

EDIT 2 If giving the user full access works, then maybe narrow it to just the permissions I put above or the managed policy AmazonAPIGatewayAdministrator. Those don't have the 'conditional' statement which may make a difference.

I also strongly recommend visiting the Amplify Discord channel. It's very active.

  • Related