I am breaking my head over this for two days now. I have a Lambda function with two foreach loops, in which SQS messages are send. The one is working the other not.
The working function:
<code>const restoreCustomers = async (): Promise<void> => {
try {
await Promise.all([
customers.map(async (customer) => {
const params: SendMessageCommandInput = {
QueueUrl: customerSqsUrl,
MessageBody: JSON.stringify(customer),
MessageGroupId: 'CUSTOMER',
MessageDeduplicationId: customer.id,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
return true
}),
])
} catch (error) {
throw error
}
}
</code>
<code>const restoreCustomers = async (): Promise<void> => {
try {
await Promise.all([
customers.map(async (customer) => {
const params: SendMessageCommandInput = {
QueueUrl: customerSqsUrl,
MessageBody: JSON.stringify(customer),
MessageGroupId: 'CUSTOMER',
MessageDeduplicationId: customer.id,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
return true
}),
])
} catch (error) {
throw error
}
}
</code>
const restoreCustomers = async (): Promise<void> => {
try {
await Promise.all([
customers.map(async (customer) => {
const params: SendMessageCommandInput = {
QueueUrl: customerSqsUrl,
MessageBody: JSON.stringify(customer),
MessageGroupId: 'CUSTOMER',
MessageDeduplicationId: customer.id,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
return true
}),
])
} catch (error) {
throw error
}
}
And this one is not:
<code>const restoreProducts = async (): Promise<void> => {
try {
await Promise.all([
products.map(async (product) => {
const params: SendMessageCommandInput = {
QueueUrl: productSqsUrl,
MessageBody: JSON.stringify(product),
MessageGroupId: 'PRODUCT',
MessageDeduplicationId: product.barcode,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
return true
}),
])
} catch (error) {
throw error
}
}
</code>
<code>const restoreProducts = async (): Promise<void> => {
try {
await Promise.all([
products.map(async (product) => {
const params: SendMessageCommandInput = {
QueueUrl: productSqsUrl,
MessageBody: JSON.stringify(product),
MessageGroupId: 'PRODUCT',
MessageDeduplicationId: product.barcode,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
return true
}),
])
} catch (error) {
throw error
}
}
</code>
const restoreProducts = async (): Promise<void> => {
try {
await Promise.all([
products.map(async (product) => {
const params: SendMessageCommandInput = {
QueueUrl: productSqsUrl,
MessageBody: JSON.stringify(product),
MessageGroupId: 'PRODUCT',
MessageDeduplicationId: product.barcode,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
return true
}),
])
} catch (error) {
throw error
}
}
What am I missing, I cant figure out what is different.
I added logging before and after sqsQlient.send()
and the loop is logging all ‘before’ logs, but none of the ‘after’ logs.
I also tried a for
loop and strangely enough this runs fine:
<code>const restoreProducts = async (): Promise<void> => {
try {
for (let idx = 0; idx < 144; idx++) {
const params: SendMessageCommandInput = {
QueueUrl: productSqsUrl,
MessageBody: JSON.stringify(products[idx]),
MessageGroupId: 'PRODUCT',
MessageDeduplicationId: products[idx].barcode,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
}
} catch (error) {
throw error
}
}
</code>
<code>const restoreProducts = async (): Promise<void> => {
try {
for (let idx = 0; idx < 144; idx++) {
const params: SendMessageCommandInput = {
QueueUrl: productSqsUrl,
MessageBody: JSON.stringify(products[idx]),
MessageGroupId: 'PRODUCT',
MessageDeduplicationId: products[idx].barcode,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
}
} catch (error) {
throw error
}
}
</code>
const restoreProducts = async (): Promise<void> => {
try {
for (let idx = 0; idx < 144; idx++) {
const params: SendMessageCommandInput = {
QueueUrl: productSqsUrl,
MessageBody: JSON.stringify(products[idx]),
MessageGroupId: 'PRODUCT',
MessageDeduplicationId: products[idx].barcode,
}
const command = new SendMessageCommand(params)
await sqsClient.send(command)
}
} catch (error) {
throw error
}
}