When passing environment variables from my lambda-stack
to my lambda function using the environment
key, I encountered an error.
Sending Variables:
environment: {
queueArn: sqsStack.sqsQueue.queueArn,
queueUrl: sqsStack.sqsQueue.queueUrl,
},
Error: The argument '{ MessageBody: string; QueueUrl: string | undefined; }' is not compatible with the parameter type 'SendMessageRequest'.
Lambda Code:
var params = {
MessageBody: "STRING_VALUE" /* required */,
QueueUrl: process.env.queueUrl /* required */,
};
sqs.sendMessage(params, function (err, data) {
if (err) console.log(err, err.stack); // An error occurred
else console.log(data); // Successful response
});
Question:
How can I ensure in TypeScript that process.env.queueUrl
always remains a string?