Skip to content

Getting "The request signature we calculated does not match the signature you provided." when creating subscriptions using aws-appsync-subscription-link and apollo client v3 #750

@lyne-jy

Description

@lyne-jy

Note: If your issue/feature-request/question is regarding the AWS AppSync service, please log it in the
official AWS AppSync forum

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Recently we upgraded from apollo client v2 to v3 so we also upgraded aws-appsync-auth-link and aws-appsync-subscription-link. When we use apollo client v3 and aws-appsync-subscription-link to create subscriptions, we get this error:

The request signature we calculated does not match the signature you provided. 
Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

The Canonical String for this request should have been
'POST
/graphql

accept:*/*
content-type:application/json; charset=UTF-8
host:xxx.appsync-api.us-west-2.amazonaws.com
x-amz-date:20230821T214203Z
x-amz-security-token:xxx

accept;content-type;host;x-amz-date;x-amz-security-token
990ebd3e582fa2e4a448047e52ebaa031c56d86b468af9fe4adfea2687c60cd3'

The String-to-Sign should have been
'AWS4-HMAC-SHA256
20230821T214203Z
20230821/us-west-2/appsync/aws4_request
5ebe6e4c844b8a6aa3333a373feef69d913d2facb886fc24a9ea55ed5a58f19c'

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
This is how we create the apollo client and the necessary links, basically following the README:

const url = credentials.graphQLEndpoint;

const auth = {
  type: AUTH_TYPE.AWS_IAM as const,
  credentials: credentials
};

const httpLink = new HttpLink({ uri: url });

const errorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    graphQLErrors.forEach(({ message, locations, path }) =>
      console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`)
    );
  }

  if (networkError) {
    console.log(`[Network error]: ${networkError}`);
  }
  this.handleAppSyncStatusChange(AppSyncStatus.ERROR);
});
const link = ApolloLink.from([
  errorLink,
  createAuthLink({ url: credentials.graphQLEndpoint, region: credentials.region, auth: auth }),
  createSubscriptionHandshakeLink(
    { url: credentials.graphQLEndpoint, region: credentials.region, auth: auth },
    httpLink
  )
]);

const appSyncClient = new ApolloClient({
  link,
  cache: new InMemoryCache()
});

When we use this client to create subscriptions, it returns the error "The request signature we calculated does not match the signature you provided." We can confirm that the credentials are correct. We also have an Amplify client that also uses the same GraphQL API, but that's working fine.

What is the expected behavior?
Return the subscription response without errors.

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?
We use:

"@apollo/client": "3.3.21",
"aws-appsync-auth-link": "3.0.7",
"aws-appsync-subscription-link": "3.1.2"
"graphql": "^15.3.0",

We've tried apollo client v2 + aws-appsync-auth-link v2.x + aws-appsync-subscription-link v2.x and this combo worked.
We tried aws-appsync v4.1.9 which also worked.
However these are in maintenance mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    investigatingAmplify is looking into the issuep2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions