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

Credential should be scoped to correct service: 'execute-api in appsync invoking restapi #5401

Closed
4 of 14 tasks
KumarHalder opened this issue Aug 31, 2024 · 3 comments
Closed
4 of 14 tasks
Labels
question A question about the Amplify Flutter libraries REST API Issues related to the API (REST) Category

Comments

@KumarHalder
Copy link

Description

I am using restapi endpoing in apigateway as a resolver for appsync. currently the api required iam authorization.

How do I configure that? Current scenario when api is open in schema.graphql.

listDriverPastRides: [Booking] @aws_cognito_user_pools @http( url: "https://nmqeco81ra.execute-api.us-east-1.amazonaws.com/Prod/api/driver/past-rides/:userId" )

Note: I am manually updating appsync with following config

{
"endpoint": "",
"authorizationConfig": {
"authorizationType": "AWS_IAM",
"awsIamConfig": {
"signingRegion": "us-east-1",
"signingServiceName": "execute-api"
}
}
}

I am attached a role, which has following trust policy

"""
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "appsync.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
"""

and adding permission fulladmin as a test for the time being.

After invoking an endpoint, I get the following error from api gateway in the cloudwatch.

"""
{
"logType": "ResponseMapping",
"path": [
"listAllDrivers"
],
"fieldName": "listAllDrivers",
"resolverArn": "arn:aws:appsync:us-east-1::apis//types/Query/resolvers/listAllDrivers",
"requestId": "b3824bf8-ee23-4737-a728-bcb887fdb126",
"context": {
"arguments": {},
"result": {
"headers": {
"Content-Length": "77",
"Content-Type": "application/json",
"Date": "Sat, 31 Aug 2024 03:26:33 GMT",
"Via": "1.1 1c83c89ce5e3ed0b002e3445f36e0a00.cloudfront.net (CloudFront)",
"x-amz-apigw-id": "dWsIhEZxIAMEbEA=",
"X-Amz-Cf-Id": "deWxKeOd26E8LZnd1eRlZiBr8uETWh-60CbrcAgsgci6k11m-hQW7g==",
"X-Amz-Cf-Pop": "IAD61-P5",
"x-amzn-ErrorType": "InvalidSignatureException",
"x-amzn-RequestId": "b3824bf8-ee23-4737-a728-bcb887fdb126",
"X-Cache": "Error from cloudfront"
},
"statusCode": 403,
"body": "{"message":"Credential should be scoped to correct service: 'execute-api'. "}"
},
"stash": {},
"outErrors": []
},
"fieldInError": true,
"errors": [
"Unable to transform the template: Template transformation yielded an empty response.."
],
"parentType": "Query",
"graphQLAPIId": "u63udlggozhkno6io5exqxscha"
}
"""

I am open to fixing this, but ideally is there an easy way to add in amplify configuration?

Thanks in advance.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

Try creating restapi as appsync resolver which is secured with iam in api gateway

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.24

Amplify Flutter Version

2.4

Deployment Method

Amplify Gen 2

Schema

No response

@github-actions github-actions bot added pending-triage This issue is in the backlog of issues to triage pending-maintainer-response Pending response from a maintainer of this repository labels Aug 31, 2024
@NikaHsn
Copy link
Member

NikaHsn commented Sep 3, 2024

@KumarHalder Amplify Gen 2 does not support REST API and we have an open feature request for this #5252. please feel free to vote for the feature request and follow the progress on the issue.

as a work around you can add rest_api to the amplicyConfig manually similar to the code snippet below:

final json = jsonDecode(amplifyConfig);
json['rest_api'] = {
      'api-name': const RestApiOutputs(
        awsRegion: 'awsRegion',
        url: 'url',
        authorizationType: APIAuthorizationType.iam,
      ).toJson(),
    };

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Sep 3, 2024
@NikaHsn NikaHsn added pending-community-response Pending response from the issue opener or other community members REST API Issues related to the API (REST) Category question A question about the Amplify Flutter libraries and removed pending-triage This issue is in the backlog of issues to triage labels Sep 3, 2024
@NikaHsn
Copy link
Member

NikaHsn commented Oct 16, 2024

@KumarHalder I hope the suggested work around works for you. since we didn't hear back I'm going to close this issue. please open a new issue if you have additional questions.

@NikaHsn NikaHsn closed this as completed Oct 16, 2024
@github-actions github-actions bot removed the pending-community-response Pending response from the issue opener or other community members label Oct 16, 2024
Copy link

This issue is now closed. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about the Amplify Flutter libraries REST API Issues related to the API (REST) Category
Projects
None yet
Development

No branches or pull requests

3 participants
@NikaHsn @KumarHalder and others