I get type error while trying to call sqsClient with a configuration object. #5706
Answered
by
RanVaknin
palashCItobuz
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
RanVaknin
Jan 23, 2024
Replies: 1 comment 1 reply
-
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 ( 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!
}); Let me know if this helps. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
palashCItobuz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Or simplified by using the pound (
!
) operator to assert non-null: