Authenticating and connecting to a database via the Amazon SQS-compatible HTTP API
Endpoint
The connection endpoint is displayed in the management console
Prerequisites
To authenticate, take these steps:
- Create a service account.
- Assign the following roles to the service account:
- To read from a data stream:
ydb.viewer. - To write to a data stream:
ydb.editor. - To create or delete a queue:
ydb.editor.
- To read from a data stream:
- Create a static access key for the service account. Save the ID and secret key to a secure location.
Authentication
Just like Amazon SQS, the Amazon SQS-compatible HTTP API uses Signature Version 4
The following parameters are required:
<access_key_id>: Static access key ID.<secret_access_key>: Secret part of the static access key.
Configure the AWS CLI:
-
Launch the interactive profile setup:
aws configure -
Specify the service account key ID you obtained earlier:
AWS Access Key ID [****************ver_]: <service_account_key_ID> -
Specify the service account secret key you obtained earlier:
AWS Secret Access Key [****************w5lb]: <service_account_secret_key> -
Specify the
ru-central1default region name:Default region name [ru-central1]: ru-central1 -
Specify
jsonas the default format for output data:Default output format [None]: json -
To view the current profile settings, run this command:
aws configure listResult:
Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************aBc1 shared-credentials-file secret_key ****************DeF2 shared-credentials-file region ru-central1 config-file ~/.aws/config
Queue creation example
This example uses the following parameters:
<sqs_api_endpoint>: Endpoint.<stream_name>: Data stream name.
-
Install the AWS CLI
if you have not done that already. -
Create a queue:
aws --endpoint "<sqs_api_endpoint>" sqs create-queue \ --queue-name "<stream_name>"This command creates a data stream with the specified name and a shared consumer named
ydb-sqs-consumer.To create a FIFO queue, specify
FifoQueue=true. We recommend appending.fifoto the queue name:aws --endpoint "<sqs_api_endpoint>" sqs create-queue \ --queue-name "<stream_name>.fifo" \ --attributes FifoQueue=true
Example of writing and reading a message
This example uses the following parameters:
<sqs_api_endpoint>: Endpoint.<stream_name>: Data stream name.
-
Install the AWS CLI
if you have not done that already. -
Get the stream
QueueUrl:QUEUE_URL="$(aws --endpoint "<sqs_api_endpoint>" sqs get-queue-url \ --queue-name "<stream_name>" \ --query 'QueueUrl' --output text)" -
Send a message to the stream:
aws --endpoint "<sqs_api_endpoint>" sqs send-message \ --queue-url "$QUEUE_URL" \ --message-body "test message" -
Read a message from the stream:
aws --endpoint "<sqs_api_endpoint>" sqs receive-message \ --queue-url "$QUEUE_URL" \ --wait-time-seconds 20 \ --max-number-of-messages 1
For details on working with Data Streams via an Amazon SQS-compatible HTTP API and more examples, refer to the YDB guides