AWS SNS/SQS
To setup AWS SNS/SQS for pub/sub, create a component of type pubsub.snssqs
. .
Warning
The above example uses secrets as plain strings. It is recommended to use [a secret store for the secrets]]().
Conforming with AWS specifications
Dapr created SNS topic and SQS queue names conform with . By default, Dapr creates an SQS queue name based on the consumer app-id
, therefore Dapr might perform name standardization to meet with AWS specifications.
SNS/SQS component behavior
When the pub/sub SNS/SQS component provisions SNS topics, the SQS queues and the subscription behave differently in situations where the component is operating on behalf of a message producer (with no subscriber app deployed), than in situations where a subscriber app is present (with no publisher deployed).
Due to how SNS works without SQS subscription in publisher only setup, the SQS queues and the subscription behave as a “classic” pub/sub system that relies on subscribers listening to topic messages. Without those subscribers, messages:
- Cannot be passed onwards and are effectively dropped
- Are not available for future subscribers (no replay of message when the subscriber finally subscribes)
SQS FIFO
Using SQS FIFO (fifo
metadata field set to "true"
) per AWS specifications provides message ordering and deduplication, but incurs a lower SQS processing throughput, among other caveats.
To avoid losing the order of messages delivered to consumers, the FIFO configuration for the SQS Component requires the concurrencyMode
metadata field set to "single"
.
Default parallel concurrencyMode
Since v1.8.0, the component supports the "parallel"
concurrencyMode
as its default mode. In prior versions, the component default behavior was calling the subscriber a single message at a time and waiting for its response.
SQS dead-letter Queues
When configuring the PubSub component with SQS dead-letter queues, the metadata fields messageReceiveLimit
and sqsDeadLettersQueueName
must both be set to a value. For messageReceiveLimit
, the value must be greater than 0
and the sqsDeadLettersQueueName
must not be empty string.
Important
When running the Dapr sidecar (daprd
) with your application on EKS (AWS Kubernetes) node/pod already attached to an IAM policy defining access to AWS resources, you must not provide AWS access-key, secret-key, and tokens in the definition of the component spec.
For local development, the is used to integrate AWS SNS/SQS. Follow these instructions to run localstack.
To run localstack locally from the command line using Docker, apply the following cmd:
docker run --rm -it -p 4566:4566 -p 4571:4571 -e SERVICES="sts,sns,sqs" -e AWS_DEFAULT_REGION="us-east-1" localstack/localstack
See for information about authentication-related attributes.
To run localstack on Kubernetes, you can apply the configuration below. Localstack is then reachable at the DNS name http://localstack.default.svc.cluster.local:4566
(assuming this was applied to the default namespace), which should be used as the endpoint
.
apiVersion: apps/v1
kind: Deployment
metadata:
name: localstack
spec:
# using the selector, we will expose the running deployments
# this is how Kubernetes knows, that a given service belongs to a deployment
selector:
matchLabels:
app: localstack
template:
metadata:
labels:
app: localstack
spec:
containers:
- name: localstack
image: localstack/localstack:latest
ports:
# Expose the edge endpoint
- containerPort: 4566
kind: Service
apiVersion: v1
metadata:
name: localstack
labels:
app: localstack
spec:
selector:
app: localstack
ports:
- protocol: TCP
port: 4566
targetPort: 4566
type: LoadBalancer
In order to run in AWS, create or assign an IAM user with permissions to the SNS and SQS services, with a policy like:
Plug the AWS account ID
and AWS account secret
into the accessKey
and secretKey
in the component metadata, using Kubernetes secrets and secretKeyRef
.
Alternatively, let’s say you want to provision the SNS and SQS assets using your own tool of choice (e.g. Terraform) while preventing Dapr from doing so dynamically. You need to enable disableEntityManagement
and assign your Dapr-using application with an IAM Role, with a policy like:
{
"Version": "2012-10-17",
{
"Sid": "YOUR_POLICY_NAME",
"Effect": "Allow",
"Action": [
"sqs:DeleteMessage",
"sqs:ReceiveMessage",
"sqs:ChangeMessageVisibility",
"sqs:GetQueueUrl",
"sqs:GetQueueAttributes",
"sns:Publish",
"sns:ListSubscriptionsByTopic",
"sns:GetTopicAttributes"
],
"Resource": [
"arn:aws:sns:AWS_REGION:AWS_ACCOUNT_ID:APP_TOPIC_NAME",
"arn:aws:sqs:AWS_REGION:AWS_ACCOUNT_ID:APP_ID"
]
}
}
In the above example, you are running your applications on an EKS cluster with dynamic assets creation (the default Dapr behavior).