0

I'm trying to run my AWS Lambda functions locally in a NodeJS environment with serverless invoke local [...] (as per https://www.serverless.com/framework/docs/providers/aws/cli-reference/invoke-local).

I keep getting error messages from appsync/graphql/apollo, stating: "Error: Network error: Response not successful: Received status code 403"

While debugging I found that I get the following: appsync.js:

const AWS = require("aws-sdk");
console.log(AWS.config.credentials); // returns null

If I try to run the same file with node appsync.js then instead of null, AWS.config.credentials returns a valid credentials object (taken from my local .aws/credentials file.

So everything is where it should be, the only problem seems to be with the serverless invoke local ... function not allowing my aws-sdk package to access my .aws/credentials file.

How do I get aws-sdk to set AWS.config.credentials?

1 Answer 1

0

So the workaround that I managed to get working was to:

  • copy and paste my aws_access_key_id and aws_secret_access_key from .aws/credentials into my .env file.
  • Replace credentials: AWS.config.credentials, in my config object as follows:
const appSyncClientConfig = {
  url: "https://xxxxxxxxx.appsync-api.eu-west-2.amazonaws.com/graphql", // from AppSync console.
  region: "eu-west-2",
  auth: {
    type: AUTH_TYPE.AWS_IAM,
    // credentials: AWS.config.credentials, REPLACED THIS WITH THE BELOW
    credentials: {
      accessKeyId: process.env.aws_access_key_id,
      secretAccessKey: process.env.aws_secret_access_key,
    },
  },
  offlineConfig: {
    keyPrefix: "public",
  },
  disableOffline: true,
};

Now it's working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.