sqs-consumer

by somaz94

Helm chartv0.1.0App 1.0.0Apache-2.0Verified publisher

KEDA-scaled AWS SQS consumer that scales to zero — Deployment + ServiceAccount (IRSA / EKS Pod Identity) + KEDA ScaledObject (aws-sqs-queue trigger) + TriggerAuthentication (podIdentity provider aws). Renders a plain Deployment when KEDA is disabled.

About this chart

sqs-consumer

Helm chart for sqs-consumer, an AWS SQS worker that KEDA scales on queue depth, down to zero pods when the queue is empty.

What it deploys

ResourceAPIPurpose
Deploymentapps/v1The consumer. replicas is omitted while KEDA is on, so the KEDA-managed HPA owns it
ServiceAccountv1Pod identity for the AWS SDK credential chain (IRSA annotation or EKS Pod Identity association) (serviceAccount.create)
ScaledObjectkeda.sh/v1alpha1aws-sqs-queue trigger on consumer.queueUrl (keda.enabled)
TriggerAuthenticationkeda.sh/v1alpha1podIdentity.provider: aws for the trigger (keda.enabled and keda.triggerAuthentication.create)

With keda.enabled: false only the Deployment (with replicaCount) and the ServiceAccount render, so the chart also works on a cluster without KEDA.

Versioning

  • Chart version is this chart's own SemVer.
  • appVersion is the ghcr.io/somaz94/sqs-consumer release the chart was tested against, and the default image tag when image.tag is empty.

Prerequisites

  • Kubernetes 1.25+
  • KEDA 2.13+ with its CRDs, for keda.enabled: true (the default). 2.13 introduced the aws pod identity provider with identityOwner / roleArn; keda.triggerAuthentication.externalID needs 2.20+, and an older CRD drops the field silently.
  • An SQS queue, and an IAM role for the consumer (see IAM)
  • On EKS: IRSA (an OIDC provider for the cluster) or the EKS Pod Identity Agent

Install

These snippets install the latest published chart. To pin an exact chart version, add --version <x.y.z>; released versions are the GitHub Release tags named sqs-consumer-<version>.

OCI registry (Helm 3.8+)

helm install order-consumer oci://ghcr.io/somaz94/charts/sqs-consumer \
  --namespace sqs --create-namespace \
  --set consumer.queueUrl=https://sqs.ap-northeast-2.amazonaws.com/123456789012/order-processing-queue \
  --set consumer.awsRegion=ap-northeast-2 \
  --set 'serviceAccount.annotations.eks\.amazonaws\.com/role-arn=arn:aws:iam::123456789012:role/sqs-consumer-role'

Classic Helm repo

helm repo add somaz94 https://charts.somaz.blog
helm repo update
helm install order-consumer somaz94/sqs-consumer \
  --namespace sqs --create-namespace \
  -f my-values.yaml

Quick examples

Scale to zero with IRSA (default mode)

KEDA reads the IRSA role from the consumer's ServiceAccount (identityOwner: workload), so one role serves both the pods and the scaler. Its trust policy must also allow the KEDA operator; see IAM.

consumer:
  queueUrl: https://sqs.ap-northeast-2.amazonaws.com/123456789012/order-processing-queue
  awsRegion: ap-northeast-2
serviceAccount:
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/sqs-consumer-role
    eks.amazonaws.com/sts-regional-endpoints: "true"

Watch 30 messages become 6 pods

queueLength: "5" is the target per pod, so 30 messages ask for 30 / 5 = 6 replicas. KEDA counts in-flight messages too (scaleOnInFlight: true), so one message per receive and a slow handler keep the queue deep long enough to watch it happen:

consumer:
  queueUrl: https://sqs.ap-northeast-2.amazonaws.com/123456789012/order-processing-queue
  awsRegion: ap-northeast-2
  maxMessages: 1
  processDelay: "10s"
serviceAccount:
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/sqs-consumer-role
keda:
  trigger:
    queueLength: "5"
for i in $(seq 1 30); do
  aws sqs send-message \
    --queue-url https://sqs.ap-northeast-2.amazonaws.com/123456789012/order-processing-queue \
    --message-body "order-$i" > /dev/null
done

kubectl -n sqs get hpa keda-hpa-order-consumer-sqs-consumer   # TARGETS 30/5 (avg), REPLICAS 6
kubectl -n sqs get deploy order-consumer-sqs-consumer -w       # 0 → 1 → 6, back to 0 after cooldownPeriod

The resource names are <release>-sqs-consumer unless the release name already contains sqs-consumer (set fullnameOverride to choose your own).

KEDA with its own role (identityOwner: keda)

The KEDA operator's IRSA role reads the queue depth, and the consumer's role only needs to receive and delete. Grant the operator role sqs:GetQueueAttributes.

consumer:
  queueUrl: https://sqs.ap-northeast-2.amazonaws.com/123456789012/order-processing-queue
  awsRegion: ap-northeast-2
keda:
  triggerAuthentication:
    identityOwner: keda

This is also the mode to use with EKS Pod Identity, because identityOwner: workload only discovers the IRSA annotation.

An explicit role for KEDA (roleArn)

KEDA assumes the named role. roleArn and identityOwner are mutually exclusive in KEDA, so clear identityOwner; the chart refuses to render with both set. externalID is optional and only applies here.

consumer:
  queueUrl: https://sqs.ap-northeast-2.amazonaws.com/123456789012/order-processing-queue
  awsRegion: ap-northeast-2
keda:
  triggerAuthentication:
    identityOwner: ""
    roleArn: arn:aws:iam::123456789012:role/keda-sqs-reader

Without KEDA

consumer:
  queueUrl: https://sqs.ap-northeast-2.amazonaws.com/123456789012/order-processing-queue
  awsRegion: ap-northeast-2
keda:
  enabled: false
replicaCount: 2

Required values

  • consumer.queueUrl: the full queue URL. The pods read it as SQS_QUEUE_URL and the trigger uses it as queueURL.
  • consumer.awsRegion: the queue's region (AWS_REGION and the trigger's awsRegion).

The chart also refuses to render when:

  • terminationGracePeriodSeconds is not greater than consumer.shutdownTimeoutSeconds (the kubelet would kill a pod that is still draining)
  • keda.triggerAuthentication.roleArn and keda.triggerAuthentication.identityOwner are both set
  • keda.triggerAuthentication.externalID is set without roleArn
  • keda.triggerAuthentication.create is false and keda.triggerAuthentication.name is empty
  • keda.maxReplicaCount is below keda.minReplicaCount, or keda.idleReplicaCount is not below keda.minReplicaCount

IAM

Two identities touch the queue: the consumer pods, which receive and delete messages, and the KEDA operator, which reads the queue depth.

The consumer's role needs, on the queue:

{
  "Effect": "Allow",
  "Action": ["sqs:ReceiveMessage", "sqs:DeleteMessage", "sqs:GetQueueAttributes"],
  "Resource": "arn:aws:sqs:ap-northeast-2:123456789012:order-processing-queue"
}

Which role KEDA uses depends on keda.triggerAuthentication:

SettingKEDA usesWhat the role needs
identityOwner: workload (chart default)The role in the consumer ServiceAccount's eks.amazonaws.com/role-arn annotation, assumed with KEDA's own tokensqs:GetQueueAttributes (already in the policy above), and a trust policy that also allows the KEDA operator ServiceAccount (below)
identityOwner: kedaThe KEDA operator's own rolesqs:GetQueueAttributes on the operator's role
roleArn: <arn>That rolesqs:GetQueueAttributes, and a trust policy that lets KEDA assume it (the statement below, or sts:AssumeRole from the operator's role)

In the default workload mode KEDA assumes the consumer's role through sts:AssumeRoleWithWebIdentity with the keda-operator ServiceAccount's token, so the role's trust policy needs a second statement next to the one for the consumer's own ServiceAccount (KEDA docs):

{
  "Effect": "Allow",
  "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/<OIDC_PROVIDER>" },
  "Action": "sts:AssumeRoleWithWebIdentity",
  "Condition": {
    "StringEquals": {
      "<OIDC_PROVIDER>:sub": "system:serviceaccount:keda:keda-operator",
      "<OIDC_PROVIDER>:aud": "sts.amazonaws.com"
    }
  }
}

Adjust keda:keda-operator if KEDA runs in another namespace or under another ServiceAccount name. Without this statement the ScaledObject reports AccessDenied and the Deployment never leaves zero.

The chart uses TriggerAuthentication.spec.podIdentity.identityOwner, not the identityOwner trigger metadata, which KEDA deprecated in v2.13 and will remove in v3.

Values reference

The tables below mirror values.yaml, which is authoritative; values.schema.json enforces the shape.

Consumer

Each consumer.* value becomes one container env variable.

KeyEnvNotes
consumer.queueUrlSQS_QUEUE_URLRequired
consumer.awsRegionAWS_REGIONRequired
consumer.waitTimeSecondsSQS_WAIT_TIME_SECONDSLong-poll wait, 0–20
consumer.maxMessagesSQS_MAX_MESSAGESMessages per receive, 1–10
consumer.visibilityTimeoutSecondsSQS_VISIBILITY_TIMEOUTKeep above the worst-case processing time
consumer.processDelayPROCESS_DELAYSimulated work per message, Go duration
consumer.concurrencyCONCURRENCYMessages processed in parallel per pod, 1–10
consumer.logLevel / consumer.logFormatLOG_LEVEL / LOG_FORMATdebug..error / json or text
consumer.shutdownTimeoutSecondsSHUTDOWN_TIMEOUTRendered as <n>s; drain time after SIGTERM
healthPortHEALTH_ADDRRendered as :<port>; probes hit /healthz and /readyz on it
extraEnv[]Appended after the variables above

KEDA

KeyPurpose
keda.enabledRender the ScaledObject and TriggerAuthentication, and drop replicas from the Deployment
keda.{pollingInterval,cooldownPeriod}Poll period, and the delay before scaling 1 → 0 (rendered only when the ScaledObject can reach zero)
keda.{minReplicaCount,maxReplicaCount,idleReplicaCount}Replica bounds; minReplicaCount: 0 is scale to zero, and idleReplicaCount accepts only 0
keda.fallback.{failureThreshold,replicas,behavior}Replicas to hold while the scaler fails; not rendered when empty
keda.horizontalPodAutoscalerConfigadvanced.horizontalPodAutoscalerConfig; defaults to a 60s scale-down stabilization window
keda.trigger.{queueLength,activationQueueLength}Target messages per pod, and the depth that wakes the Deployment from zero
keda.trigger.{scaleOnInFlight,scaleOnDelayed}Count in-flight and delayed messages toward the depth
keda.trigger.metadataExtraExtra trigger metadata, e.g. awsEndpoint
keda.triggerAuthentication.{create,name,kind}Render a TriggerAuthentication, or reference an existing (Cluster)TriggerAuthentication
keda.triggerAuthentication.{identityOwner,roleArn,externalID}podIdentity settings; see IAM
keda.scaledObjectExtraMerged into the ScaledObject spec last

Pod and metadata

KeyPurpose
image.{repository,tag,pullPolicy}Tag defaults to appVersion
imagePullSecretsExisting pull secrets
replicaCountUsed only with keda.enabled: false
terminationGracePeriodSecondsMust exceed consumer.shutdownTimeoutSeconds
serviceAccount.{create,name,annotations,automountServiceAccountToken}IRSA annotation goes in annotations
resources, livenessProbe, readinessProbeContainer resources and probes
podSecurityContext / securityContextNon-root, read-only root filesystem, all capabilities dropped, RuntimeDefault seccomp
podAnnotations, podLabels, nodeSelector, tolerations, affinity, topologySpreadConstraints, priorityClassNamePod scheduling and metadata
extraVolumes / extraVolumeMountse.g. an emptyDir on /tmp if the image needs a writable path
commonLabels / commonAnnotations / resourceMetadata.*Labels and annotations per resource kind
specExtra / podTemplateExtraEscape hatches into the Deployment spec and Pod spec

License

Apache-2.0

Deploy sqs-consumer with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has sqs-consumer on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartsqs-consumer is pinned at v0.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply