Options / config parameters
A tomodachi.Service
extended service class may specify a service class attribute named options
(as a tomodachi.Options
object that provides typed configuration and easy path traversal) for additional configuration related to AWS SNS+SQS, AMQP, HTTP, keep-alives, graceful termination timeouts, etc.
import json
import tomodachi
class Service(tomodachi.Service):
name = "http-example"
options = tomodachi.Options(
http=tomodachi.Options.HTTP(
port=80,
content_type="application/json; charset=utf-8",
real_ip_from=[
"127.0.0.1/32",
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
],
keepalive_timeout=5,
max_keepalive_requests=20,
),
watcher=tomodachi.Options.Watcher(
ignored_dirs=["node_modules"],
),
)
@tomodachi.http("GET", r"/health")
async def health_check(self, request):
return 200, json.dumps({"status": "healthy"})
# Specify custom 404 catch-all response
@tomodachi.http_error(status_code=404)
async def error_404(self, request):
return json.dumps({"error": "not-found"})
Here follows a table of available config parameters that can be applied as options
.
Configuration key | Description | Default value |
---|---|---|
| TCP port (integer value) to listen for incoming connections. |
|
| Network interface to bind TCP server to. |
|
| If set to |
|
| Enables connections to use keep-alive if set to an integer value over |
|
| An optional number (integer value) of requests which is allowed for a keep-alive connection. After the specified number of requests has been done, the connection will be closed. An option value of |
|
| An optional maximum time in seconds (int) for which keep-alive connections are kept open. If a keep-alive connection has been kept open for more than |
|
| The client’s maximum size in a request, as an integer, in bytes. |
|
| The number of seconds to wait for functions called via HTTP to gracefully finish execution before terminating the service, for example if service received a |
|
| Header to read the value of the client's real IP address from if service operates behind a reverse proxy. Only used if |
|
| IP address(es) or IP subnet(s) / CIDR. Allows the |
|
| Default content-type header to use if not specified in the response. |
|
| If set to the default value (boolean) |
|
|
|
|
… … | ||
| The AWS region to use for SNS+SQS pub/sub API requests. |
|
| The AWS access key to use for SNS+SQS pub/sub API requests. |
|
| The AWS secret to use for SNS+SQS pub/sub API requests. |
|
| A prefix to any SNS topics used. Could be good to differentiate between different dev environments. |
|
| A prefix to any SQS queue names used. Could be good to differentiate between different dev environments. |
|
| If set, will set the KMS key (alias or id) to use for encryption at rest on the SNS topics created by the service or subscribed to by the service. Note that an option value set to an empty string ( |
|
| If set, will set the KMS key (alias or id) to use for encryption at rest on the SQS queues created by the service or for which the service consumes messages on. Note that an option value set to an empty string ( |
|
| If set, will set the KMS data key reuse period value on the SQS queues created by the service or for which the service consumes messages on. If the option is completely unset or set to |
|
… … | ||
| Configurable endpoint URL for AWS SNS – primarily used for testing during development using fake services / fake endpoints. |
|
| Configurable endpoint URL for AWS SQS – primarily used for testing during development using fake services / fake endpoints. |
|
… … | ||
| Host address / hostname for RabbitMQ server. |
|
| Host post for RabbitMQ server. |
|
| Login credentials. |
|
| Login credentials. |
|
| The AMQP exchange name to use in the service. |
|
| A prefix to add to any AMQP routing keys provided in the service. |
|
| A prefix to add to any AMQP queue names provided in the service. |
|
| AMQP virtualhost settings. |
|
| TLS can be enabled for supported host connections. |
|
| The heartbeat timeout value defines after what period of time the peer TCP connection should be considered unreachable (down) by RabbitMQ and client libraries. |
|
| TTL set on newly created queues. |
|
… … | ||
| Directories / folders that the automatic code change watcher should ignore. Could be used during development to save on CPU resources if any project folders contains a large number of file objects that doesn't need to be watched for code changes. Already ignored directories are |
|
| Additions to the list of file endings that the watcher should monitor for file changes. Already followed file endings are |
|
… … | ||
|
Updated 11 days ago