Choosing a backend#
The package has one shared core and two clients behind it. You pick the client with the class of the broker. Handlers, routers, tests, middlewares and the exceptions you catch are the same for both.
CapoSqsBroker |
AiobotocoreSqsBroker |
|
|---|---|---|
| Extra | capo |
aiobotocore |
| Libraries | capo-sqs, capo-sns over zapros |
aiobotocore |
| Credentials | capo's chain: environment, assume-role, web identity, SSO, profile, process, ECS, EC2 metadata | botocore's chain, an AioSession, profiles |
| Backend arguments | credentials_provider, retry_mode, retry_max_attempts |
session, config |
from faststream import FastStream
from faststream_sqs_sns import CapoSqsBroker
broker = CapoSqsBroker(region="eu-central-1", retry_max_attempts=5)
app = FastStream(broker)
@broker.subscriber("orders")
async def bill(order: dict[str, int]) -> None: ...
from botocore.config import Config
from faststream import FastStream
from faststream_sqs_sns import AiobotocoreSqsBroker
broker = AiobotocoreSqsBroker(
region="eu-central-1",
# merged over the timeouts and the pool size the broker computes
config=Config(retries={"max_attempts": 5}),
)
app = FastStream(broker)
@broker.subscriber("orders")
async def bill(order: dict[str, int]) -> None: ...
Cost#
On a LocalStack run of the same calls on one machine, capo spent about 1.6 times less client CPU per call and 3 times less memory than aiobotocore, and imported 2.4 times faster. Use capo for a new service. Use aiobotocore when the service already runs botocore: shared sessions, named profiles and the IAM tooling that reads the botocore configuration.
Both backends pass the full live test suite against LocalStack.
Credentials#
Without a security argument, each backend resolves credentials on its own.
capo reads the environment, assume-role, web identity, SSO, the shared profile, a credential
process, the ECS container and the EC2 instance metadata. SSO profiles need the capo SSO extras
next to the broker's capo extra:
pip install "faststream-sqs-sns[capo]" "capo-sqs[sso]" "capo-sns[sso]"
credentials_provider takes a capo CredentialsProvider and wins over security.
aiobotocore resolves credentials through botocore. Pass an AioSession to select a profile or a
custom credential resolver:
from aiobotocore.session import AioSession
from faststream_sqs_sns import AiobotocoreSqsBroker
# a named profile of ~/.aws/config, resolved by botocore's own credential chain
broker = AiobotocoreSqsBroker(session=AioSession(profile="billing"))
config takes a botocore.config.Config. It is merged over the broker's own settings
(connect_timeout, read_timeout and the pool size), so only the fields you set change.
AwsSecurity passes a static key pair to either backend. See
LocalStack and credentials.
Missing extras#
Both brokers are imported on first use. from faststream_sqs_sns import SqsRouter, SqsQueue
works with either extra alone. Using CapoSqsBroker without the capo extra raises an
ImportError that names the extra and the install command; the same holds for
AiobotocoreSqsBroker.
capo and zapros change their API between minor releases, so the extras pin each to one minor
line. SqsBroker is the shared core. It is exported for annotations and isinstance checks,
and constructing it directly raises TypeError.
Connections and timeouts#
Both backends take the same arguments:
| Argument | Default | Meaning |
|---|---|---|
connect_timeout |
5 seconds | Time to open a connection. |
read_timeout |
30 seconds | Time to wait for a response. It must exceed the wait_time of every subscriber by 5 seconds; the broker checks it when a subscriber starts. |
max_connections |
one per poll loop plus 10 | Connections of the SQS client. |