Created
November 17, 2019 15:01
-
-
Save hhatto/feb0132f62f0df53b43bad0f79112b59 to your computer and use it in GitHub Desktop.
rusoto sns example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use rusoto_core::credential::ProfileProvider; | |
use rusoto_core::request::HttpClient; | |
use rusoto_core::Region; | |
use rusoto_sns::{ | |
Sns, | |
SnsClient, | |
CreatePlatformApplicationInput, | |
CreatePlatformEndpointInput, | |
SetPlatformApplicationAttributesInput, | |
SetEndpointAttributesInput, | |
GetSMSAttributesInput, | |
SetSMSAttributesInput, | |
GetSubscriptionAttributesInput, | |
SetSubscriptionAttributesInput, | |
}; | |
fn create(client: &SnsClient) { | |
let mut sns_input_attrib = HashMap::new(); | |
sns_input_attrib.insert( | |
"PlatformCredential".to_string(), | |
"AIzaSyAJelPhIugDkvkOZbE2rq8T0xLhr-iPg1Y".to_string() | |
); | |
sns_input_attrib.insert( | |
"PlatformPrincipal".to_string(), | |
"YOUR_PLATFORM_PRINCIPAL".to_string(), | |
); | |
let sns_input = CreatePlatformApplicationInput { | |
name: "example_platform_name".to_string(), | |
platform: "GCM".to_string(), | |
attributes: sns_input_attrib, | |
}; | |
let _ = match client.create_platform_application(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn set_attrib(client: &SnsClient) { | |
let mut sns_input_attrib = HashMap::new(); | |
sns_input_attrib.insert( | |
"PlatformCredential".to_string(), | |
"YOUR_PLATFORM_CREDENTIAL".to_string() | |
); | |
let sns_input = SetPlatformApplicationAttributesInput { | |
platform_application_arn: "ARN/GCM/example_platform_name".to_string(), | |
attributes: sns_input_attrib, | |
}; | |
let _ = match client.set_platform_application_attributes(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn create_endpoint(client: &SnsClient) { | |
let mut sns_input_attrib = HashMap::new(); | |
sns_input_attrib.insert( | |
"Enabled".to_string(), | |
"false".to_string() | |
); | |
let sns_input = CreatePlatformEndpointInput { | |
platform_application_arn: "ARN/GCM/example_platform_name".to_string(), | |
token: "aaa".to_string(), | |
custom_user_data: None, | |
attributes: Some(sns_input_attrib), | |
}; | |
let _ = match client.create_platform_endpoint(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn set_endpoint_attrib(client: &SnsClient) { | |
let mut sns_input_attrib = HashMap::new(); | |
sns_input_attrib.insert( | |
"Enabled".to_string(), | |
"false".to_string() | |
); | |
let sns_input = SetEndpointAttributesInput { | |
endpoint_arn: "ARN/GCM/example_platform_name/ID".to_string(), | |
attributes: sns_input_attrib, | |
}; | |
let _ = match client.set_endpoint_attributes(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn get_sms_attrib(client: &SnsClient) { | |
let sns_input = GetSMSAttributesInput { | |
attributes: Some(vec!["DefaultSMSType".to_string()]), | |
}; | |
let _ = match client.get_sms_attributes(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn set_sms_attrib(client: &SnsClient) { | |
let mut sns_input_attrib = HashMap::new(); | |
sns_input_attrib.insert( | |
"DefaultSMSType".to_string(), | |
"Promotional".to_string() | |
); | |
let sns_input = SetSMSAttributesInput { | |
attributes: sns_input_attrib, | |
}; | |
let _ = match client.set_sms_attributes(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn get_subscription_attrib(client: &SnsClient) { | |
let mut sns_input_attrib = HashMap::new(); | |
sns_input_attrib.insert( | |
"DefaultSMSType".to_string(), | |
"Promotional".to_string() | |
); | |
let sns_input = GetSubscriptionAttributesInput { | |
subscription_arn: "ARN:SUBSCRIPTION_ID".to_string(), | |
}; | |
let _ = match client.get_subscription_attributes(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn set_subscription_attrib(client: &SnsClient) { | |
let mut sns_input_attrib = HashMap::new(); | |
sns_input_attrib.insert( | |
"DefaultSMSType".to_string(), | |
"Promotional".to_string() | |
); | |
let sns_input = SetSubscriptionAttributesInput { | |
subscription_arn: "ARN:SUBSCRIPTION_ID".to_string(), | |
attribute_name: "DeliveryPolicy".to_string(), | |
attribute_value: None, | |
}; | |
let _ = match client.set_subscription_attributes(sns_input).sync() { | |
Ok(output) => { | |
println!("{:?}", output); | |
Some(output) | |
}, | |
Err(e) => { | |
println!("Error: {:?}", e); | |
None | |
}, | |
}; | |
} | |
fn main() { | |
let cred_filepath = format!("{}/.aws/credentials", dirs::home_dir().unwrap().to_str().unwrap()); | |
let creds = ProfileProvider::with_configuration(cred_filepath, "default"); | |
let client = SnsClient::new_with( | |
HttpClient::new().expect("fail create client"), | |
creds.clone(), | |
Region::UsEast1, | |
); | |
// create(&client); | |
// set_attrib(&client); | |
// create_endpoint(&client); | |
// set_endpoint_attrib(&client); | |
// get_sms_attrib(&client); | |
// set_sms_attrib(&client); | |
// get_subscription_attrib(&client); | |
set_subscription_attrib(&client); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment