I have a lambda function with an exacution role with this policies:
- AWSLambdaBasicExecutionRole ("logs:CreateLogStream", "logs:PutLogEvents")
- a custom policy ({
"Effect": "Allow",
"Action": [
"sqs:SendMessage",
"sqs:ListQueues"
],
"Resource": [
"arn:aws:sqs:myqueue"
]
})
- AWSCodeCommitReadOnly
the my sqs queue has aan access policy:
{
"Sid": "AllowLambdaAccess",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::myLambdaServiceRole"
},
"Action": "SQS:SendMessage",
"Resource": "arn:aws:sqs:mySqsQueue"
}
the lambda function and the queue are in the same region. No vpc configured for the lambda function.
proplem is lambda times out and can't push messages to sqs
code for lambda is pretty standard:
const { SQSClient, SendMessageCommand } = require('@aws-sdk/client-sqs');
const sqsClient = new SQSClient({ region: 'us-east-1' });
const queueUrl = 'https://sqs.us-east-1.amazonaws.com/XXXXXXXXXXX/MySqsQueue';
const messageParams = {
QueueUrl: queueUrl,
MessageBody: JSON.stringify({MY OBJECT DEFINED HERE})
};
try {
const command = new SendMessageCommand(messageParams);
await sqsClient.send(command);
console.log('Message sent to SQS queue successfully.');
} catch (error) {
console.error('Error sending message to SQS:', error);
}
any idea what I am doing wrong?
thanks for helping me. arns are correct, in my example above I just simplified a bit. Logs in lambda just say "Task timed out after 5.04 seconds". I tried to increase the timeout to 1 min, same result. Anyway it shouldn't take long, as for test purposes I commented out everything and left only the sqs call bit. No logs on the sqs side. the sqs queue works as expected if I manually put a message from the console.