---
title: Using Scaleway Topics and Events with the AWS-CLI
description: This page explains how to use Scaleway Topics and Events for creating topics and sending and receiving messages with the AWS CLI
tags: messaging sns aws-cli cli aws messages subscribe publish topics
dates:
  validation: 2025-10-16
  posted: 2023-04-04
---
import Requirements from '@macros/iam/requirements.mdx'


The AWS-CLI is an open-source tool built on top of the AWS SDK for Python (Boto) that provides commands for interacting with AWS services. Once you have [connected Scaleway Topics and Events to the AWS-CLI](/topics-and-events/api-cli/connect-aws-cli/), you can start creating, listing and managing your topics, sending messages and much more, all from your command line.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- Valid [credentials](/topics-and-events/how-to/create-credentials/) for Topics and Events
- [Connected Topics and Events to the AWS-CLI](/topics-and-events/api-cli/connect-aws-cli/)
- [jq](https://stedolan.github.io/jq/download/) installed on your machine


## Getting started with Topics and Events

1. Use the following command to create a topic:

    ```bash
    aws sns create-topic --name MyTopic | tee my-topic.json
    ```

2. Use the following command to list existing topics:

    ```bash
    aws sns list-topics
    ```

## Preparing and subscribing to an HTTP/HTTPS target for Topics and Events messages

1. Get the public endpoint of the HTTP server you want to forward your messages to.

2. Use the following command to configure a subscription to push each new message sent on the topic to the HTTP server:

    ```bash
    aws sns subscribe --topic-arn $(jq -r .TopicArn my-topic.json) --protocol http --notification-endpoint <YOUR-HTTP-ENDPOINT> | tee my-subscription.json
    ```

3. Find the HTTP request received by the HTTP server. It should have a body in JSON matching the following format. It contains the information necessary to complete the subscription process:

    ```json
    {
        "Type": "SubscriptionConfirmation",
        "Token": "<REDACTED-CONFIRMATION-TOKEN>",
        "MessageId": "<REDACTED-MESSAGE-ID>",
        "TopicArn": "arn:scw:sns:fr-par:<REDACTED-ID>:MyTopic",
        "Message": "You have chosen to subscribe to the topic arn:scw:sns:fr-par:<REDACTED-ID>:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
        "Timestamp": "2022-06-29T10:03:34Z",
        "SignatureVersion": "1",
        "Signature": "<REDACTED-SIGNATURE>",
        "SigningCertURL": "http://<REDACTED-URL>/SNStest.crt",
        "SubscribeURL": "<THE-CONFIRMATION-LINK>" // Get the confirmation link located here
    }
    ```

4. Use the following command to confirm the subscription:

    ```bash
    curl "<THE-CONFIRMATION-LINK>"
    ```

## Preparing and subscribing to a lambda (Scaleway Serverless Functions) target for Topics and Events messages

1. Create the function following the steps detailed in the [Scaleway Functions Quickstart](/serverless-functions/quickstart/).

2. Get the function endpoint from the [Scaleway console](https://console.scaleway.com/functions) under "Functions" -> "[YOUR-FUNCTION-NAMESPACE]" -> "[YOUR-FUNCTION-NAME]" -> "Function Settings" tab -> "Function Endpoint"

    <Message type="important">
    Only the main generated endpoint of the function will work, not the aliases. The endpoint should match the following format:

    ```bash
    https://<GENERATED-NAMESPACE-ENDPOINT>-<YOUR-FUNCTION-NAME>.functions.fnc.fr-par.scw.cloud
    example: "https://mynamespacexxxxxxxx-myfunction.functions.fnc.fr-par.scw.cloud)"
    ```
    </Message>

3. Use the following command to configure a subscription to push each new message sent on this topic to the function:

    ```bash
    aws sns subscribe --topic-arn $(jq -r .TopicArn my-topic.json) --protocol lambda --notification-endpoint <YOUR-FUNCTION-ENDPOINT> | tee my-subscription.json

    ```
    
## Continuing with Topics and Events

1. Use the following command to list subscriptions:

    ```bash
    aws sns list-subscriptions
    ```

2. Use the following command to publish a message on the topic:

    ```bash
    aws sns publish --topic-arn $(jq -r .TopicArn my-topic.json) --message "Hello world!" --message-deduplication-id $(date +%s)
    ```

3. Use the following command to read the message received on a **Scaleway Queues** target:

    <Message type ="note">
        - For **HTTP**/**HTTPS** targets, you should have received the message on your server
        - For **lambda** targets, your function should have been called with the message as argument
    </Message>

    ```bash
    aws sqs receive-message --queue-url $(jq -r .QueueUrl my-queue.json) | tee message1.json
    ```

4. Use the following command to delete the message received on a **Scaleway Queues** target. This is necessary to prevent it from being re-queued:

    ```bash
    aws sqs delete-message --queue-url $(jq -r .QueueUrl my-queue.json) --receipt-handle $(jq -r .Messages[0].ReceiptHandle message1.json)
    ```

5. Use the following command to delete the subscription:

    ```bash
    aws sns unsubscribe --subscription-arn $(jq -r .SubscriptionArn my-subscription.json)
    ```

6. Use the following command to delete the Scaleway queue (if you had a Scaleway Queues target):

    ```bash
    aws sqs delete-queue --queue-url $(jq -r .QueueUrl my-queue.json)
    ```

    <Message type="tip">
    For **lambda**, delete the function (if necessary), using the [Scaleway console](https://console.scaleway.com/functions)
    </Message>

7. Use the following command to delete the topic:

    ```bash
    aws sns delete-topic --topic-arn $(jq -r .TopicArn my-topic.json)
    ```
