# IAM policy: Lambda reading from an SQS queue

IAM policy examples · Updated 17 November 2026

**Short answer:** The function's execution role needs sqs:ReceiveMessage, sqs:DeleteMessage and sqs:GetQueueAttributes on the queue ARN, plus CloudWatch Logs permissions. If the queue is encrypted with a customer managed KMS key, add kms:Decrypt on that key.

## The policy

```
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ConsumeQueue",
      "Effect": "Allow",
      "Action": [
        "sqs:ReceiveMessage",
        "sqs:DeleteMessage",
        "sqs:GetQueueAttributes"
      ],
      "Resource": "arn:aws:sqs:eu-west-2:123456789012:orders-queue"
    },
    {
      "Sid": "DecryptQueueMessages",
      "Effect": "Allow",
      "Action": "kms:Decrypt",
      "Resource": "arn:aws:kms:eu-west-2:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab"
    },
    {
      "Sid": "WriteLogs",
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "arn:aws:logs:eu-west-2:123456789012:log-group:/aws/lambda/orders-worker:*"
    }
  ]
}
```

## Why these three SQS actions

With an SQS trigger, your code never calls SQS itself. Lambda's event source mapping polls the queue **using the function's execution role**, invokes your function with a batch, and deletes the messages when the invocation succeeds.

- `sqs:ReceiveMessage`: the long-poll that fetches batches.
- `sqs:DeleteMessage`: removes processed messages. Without it, every message reappears after the visibility timeout and is processed again.
- `sqs:GetQueueAttributes`: Lambda reads the queue's settings, such as the visibility timeout, when you create the mapping.

This is the same set as the managed policy `AWSLambdaSQSQueueExecutionRole`, but limited to one queue.

## Create the trigger

```
aws iam put-role-policy --role-name orders-worker-lambda \
  --policy-name consume-orders-queue --policy-document file://sqs.json

aws lambda create-event-source-mapping --function-name orders-worker \
  --event-source-arn arn:aws:sqs:eu-west-2:123456789012:orders-queue \
  --batch-size 10 --function-response-types ReportBatchItemFailures
```

If the role is missing a permission, `create-event-source-mapping` fails straight away with an error saying the execution role does not have permission to call ReceiveMessage (or GetQueueAttributes) on SQS. Fix the policy and run it again.

## Variations

- **SSE-SQS (SQS-managed encryption)** needs no KMS permission; drop the second statement.
- **FIFO queues** use the same three actions; the ARN ends in `.fifo`.
- **The function also sends messages** (for example to the next queue): add `sqs:SendMessage` on *that* queue's ARN, and `kms:GenerateDataKey` if it uses a customer managed key.
- **Queue in another account**: the queue's access policy must also allow the role's ARN to receive, delete and get attributes.

## Watch it work

```
aws lambda list-event-source-mappings --function-name orders-worker \
  --query 'EventSourceMappings[].[UUID,State,LastProcessingResult]' --output table

aws sqs get-queue-attributes --queue-url https://sqs.eu-west-2.amazonaws.com/123456789012/orders-queue \
  --attribute-names ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible
```

A mapping stuck in a failed state with a permissions message in `LastProcessingResult` means the role changed after the trigger was created.

Batch failures are best handled with partial batch responses (`ReportBatchItemFailures`), which needs no extra permission and avoids reprocessing the messages that already succeeded.

## Common mistakes

- **Adding the permissions to the queue policy only.** The poller uses the execution role, so the role needs them; the queue policy only matters across accounts.
- **Forgetting the dead-letter queue setup.** The DLQ is configured on the source queue's redrive policy and needs no Lambda permission, but a queue without one retries a poison message until it expires. See [redrive a DLQ](https://cloudconsole.dev/how-to/redrive-sqs-dead-letter-queue).
- **Granting `sqs:*`**: it includes `sqs:PurgeQueue` and `sqs:DeleteQueue`. Neither is needed by a consumer.

## Questions

### What permissions does Lambda need to read from SQS?

sqs:ReceiveMessage, sqs:DeleteMessage and sqs:GetQueueAttributes on the queue, in the function's execution role, plus kms:Decrypt if the queue uses a customer managed key.

### Does the SQS queue policy need to allow Lambda?

Not in the same account. The event source mapping uses the execution role. A queue policy is only needed when the queue is in a different account.

## When this happens away from your desk

A consumer that stopped deleting messages shows up as a queue that only ever grows. Watching queue depth and the age of the oldest message from a phone catches it before customers do.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Using Lambda with Amazon SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html)
- [Actions, resources, and condition keys for Amazon SQS](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonsqs.html)

## Related

- [Lambda execution role: trust policy and basic permissions](https://cloudconsole.dev/iam/lambda-execution-role)
- [aws lambda create-event-source-mapping](https://cloudconsole.dev/cli/lambda-create-event-source-mapping)
- [How to redrive messages from an SQS dead-letter queue](https://cloudconsole.dev/how-to/redrive-sqs-dead-letter-queue)
- [IAM policy: kms:Decrypt on one key](https://cloudconsole.dev/iam/kms-decrypt)
- [How to check SQS queue size](https://cloudconsole.dev/how-to/check-sqs-queue-depth)
- [ABAC: tag-based access control policy example](https://cloudconsole.dev/iam/abac-tags)

---

Source: https://cloudconsole.dev/iam/lambda-sqs-trigger

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
