Unverified Commit 07c2ccdc authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Add SNS & example (#450)

* Add SNS & example

* it's helpful if you add the model :sweatsmile:

* Rename binaries to avoid conflict
parent fdc58eef
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
[package]
name = "sns"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sns = { package = "aws-sdk-sns", path = "../../build/aws-sdk/sns" }
tokio = { version = "1", features = ["full"] }
tracing-subscriber = "0.2.18"

[[bin]]
name = "sns-hello-world"
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

use sns::Region;
use std::process::exit;

#[tokio::main]
async fn main() -> Result<(), sns::Error> {
    tracing_subscriber::fmt::init();
    let conf = sns::Config::builder()
        .region(Region::new("us-east-2"))
        .build();
    let client = sns::Client::from_conf(conf);
    let topics = client.list_topics().send().await?;
    let mut topics = topics.topics.unwrap_or_default();
    let topic_arn = match topics.pop() {
        Some(topic) => topic.topic_arn.expect("topics have ARNs"),
        None => {
            eprintln!("No topics in this account. Please create a topic to proceed");
            exit(1);
        }
    };
    println!("receiving on `{}`", topic_arn);
    let rsp = client
        .subscribe()
        .topic_arn(&topic_arn)
        .protocol("email")
        .endpoint("some.email.address@example.com")
        .send()
        .await?;
    println!("added a subscription: {:?}", rsp);

    let rsp = client
        .publish()
        .topic_arn(&topic_arn)
        .message("hello sns!")
        .send()
        .await?;
    println!("published a message: {:?}", rsp);

    // If you set this to your email address, you should get an email from SNS
    Ok(())
}
+1 −1
Original line number Diff line number Diff line
@@ -12,4 +12,4 @@ tokio = { version = "1", features = ["full"] }
tracing-subscriber = "0.2.18"

[[bin]]
name = "hello-world"
name = "sqs-hello-world"
+2764 −0

File added.

Preview size limit exceeded, changes collapsed.