Skip to content

I get type error while trying to call sqsClient with a configuration object. #5706

Answered by RanVaknin
palashCItobuz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @palashCItobuz ,

The typescript compiler complains about those values being potentially undefined.

You can assert that they are not null by using an if block:

if (process.env.AWS_ACCESSKEY && process.env.AWS_SECRETKEY){
  const sqs = new SQSClient({
    apiVersion: process.env.AWS_SQS_APIVERSION,
    credentials: {
      accessKeyId: process.env.AWS_ACCESSKEY,
      secretAccessKey: process.env.AWS_SECRETKEY,
    },
    region: process.env.AWS_S3_REGION
  });
} else {
  throw new Error("SDK cannot be initialized with undefined credentials")
}

Or simplified by using the pound (!) operator to assert non-null:

const sqs = new SQSClient({
  apiVersion: process.env.AWS_SQS_APIVERSION,
  cre…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@palashCItobuz
Comment options

Answer selected by palashCItobuz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants