From 6133c73af8dc35a818b9a59627bf968ee991dce5 Mon Sep 17 00:00:00 2001 From: Partik Date: Wed, 10 Jul 2024 17:37:27 +0530 Subject: [PATCH] Completed AWS package Signed-off-by: Partik --- rustcloud/src/aws/aws_apis/compute/aws_ec2.rs | 282 ++++++++---------- rustcloud/src/aws/aws_apis/compute/aws_ecs.rs | 99 ++++-- rustcloud/src/aws/aws_apis/compute/aws_eks.rs | 193 ++++++++---- .../src/aws/aws_apis/compute/aws_paas.rs | 0 .../src/aws/aws_apis/database/aws_dynamodb.rs | 74 +++-- .../aws/aws_apis/management/aws_monitoring.rs | 63 +++- rustcloud/src/aws/aws_apis/network/aws_dns.rs | 57 +++- .../aws/aws_apis/network/aws_loadbalancer.rs | 71 ++++- .../src/aws/aws_apis/security/aws_iam.rs | 77 +++-- .../aws_apis/security/aws_keymanagement.rs | 70 ++++- .../aws_apis/storage/aws_archival_storage.rs | 70 ++++- .../aws/aws_apis/storage/aws_block_storage.rs | 52 +++- .../aws_apis/storage/aws_storage_bucket.rs | 64 +++- rustcloud/src/main.rs | 1 - rustcloud/src/tests/archival_operations.rs | 36 +-- rustcloud/src/tests/block_operations.rs | 27 +- rustcloud/src/tests/bucket_operations.rs | 78 +++++ rustcloud/src/tests/dns_operations.rs | 74 ++--- rustcloud/src/tests/dynamodb_operations.rs | 31 +- rustcloud/src/tests/ec2_operations.rs | 58 ++-- rustcloud/src/tests/ecs_operations.rs | 45 ++- rustcloud/src/tests/eks_operations.rs | 55 ++-- rustcloud/src/tests/iam_operations.rs | 29 +- rustcloud/src/tests/kms_operations.rs | 36 ++- .../src/tests/loadbalancer_operations.rs | 28 +- rustcloud/src/tests/mod.rs | 3 +- rustcloud/src/tests/monitoring_operations.rs | 20 +- 27 files changed, 1089 insertions(+), 604 deletions(-) delete mode 100644 rustcloud/src/aws/aws_apis/compute/aws_paas.rs create mode 100644 rustcloud/src/tests/bucket_operations.rs diff --git a/rustcloud/src/aws/aws_apis/compute/aws_ec2.rs b/rustcloud/src/aws/aws_apis/compute/aws_ec2.rs index f2ff6a1..8d4c8d3 100644 --- a/rustcloud/src/aws/aws_apis/compute/aws_ec2.rs +++ b/rustcloud/src/aws/aws_apis/compute/aws_ec2.rs @@ -1,7 +1,8 @@ #![allow(clippy::result_large_err)] use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{types::Tag, Client, Error}; +use aws_sdk_ec2::{operation::run_instances::RunInstancesError, types::Tag, Client, Error}; + // use clap::Parser; pub async fn create_instance(client: &Client, ami_id: &str) -> Result<(), Error> { @@ -12,185 +13,162 @@ pub async fn create_instance(client: &Client, ami_id: &str) -> Result<(), Error> .min_count(1) .max_count(1) .send() - .await?; - - if run_instances.instances().is_empty() { - panic!("No instances created."); - } - - println!("Created instance."); - - let instance_id = run_instances.instances()[0].instance_id().unwrap(); - client - .create_tags() - .resources(instance_id) - .tags( - Tag::builder() - .key("Name") - .value("From SDK Examples") - .build(), - ) - .send() - .await?; - - println!("Created {instance_id} and applied tags.",); - - Ok(()) + .await; + + match run_instances { + Ok(run_instances) => { + if run_instances.instances().is_empty() { + panic!("No instances created."); + let instance_id = run_instances.instances()[0].instance_id().unwrap(); + client + .create_tags() + .resources(instance_id) + .tags( + Tag::builder() + .key("Name") + .value("From SDK Examples") + .build(), + ) + .send() + .await.unwrap(); + + println!("Created {instance_id} and applied tags.",); + + } + Ok(()) + } + Err(err) => { + println!("Error: {:?}", err); + Err(err.into()) + } + } +} pub async fn show_state(client: &Client, ids: Option>) -> Result<(), Error> { let resp = client .describe_instances() .set_instance_ids(ids) .send() - .await?; - - for reservation in resp.reservations() { - for instance in reservation.instances() { - println!("Instance ID: {}", instance.instance_id().unwrap()); - println!( - "State: {:?}", - instance.state().unwrap().name().unwrap() - ); - println!(); + .await; + + match resp { + Ok(result) => { + for reservation in result.reservations() { + for instance in reservation.instances() { + println!("Instance ID: {}", instance.instance_id().unwrap()); + println!( + "State: {:?}", + instance.state().unwrap().name().unwrap() + ); + println!(); + } + } + Ok(()) + }, + Err(e) => { + println!("Error: {:?}", e); + Err(e.into()) } } - - Ok(()) } -pub async fn show_all_events(client: &Client) -> Result<(), Error> { - let resp = client.describe_regions().send().await.unwrap(); - - for region in resp.regions.unwrap_or_default() { - let reg: &'static str = Box::leak(Box::from(region.region_name().unwrap())); - let region_provider = RegionProviderChain::default_provider().or_else(reg); - let config = aws_config::from_env().region(region_provider).load().await; - let new_client = Client::new(&config); - let resp = new_client.describe_instance_status().send().await; - - println!("Instances in region {}:", reg); - println!(); - - for status in resp.unwrap().instance_statuses() { - println!( - " Events scheduled for instance ID: {}", - status.instance_id().unwrap_or_default() - ); - for event in status.events() { - println!(" Event ID: {}", event.instance_event_id().unwrap()); - println!(" Description: {}", event.description().unwrap()); - println!(" Event code: {}", event.code().unwrap().as_ref()); +pub async fn show_all_events(client: &Client) -> Result<(), Error> { + let resp = client.describe_regions().send().await; + match resp { + Ok(result) => { + for region in result.regions.unwrap_or_default() { + let reg: &'static str = Box::leak(Box::from(region.region_name().unwrap())); + let region_provider = RegionProviderChain::default_provider().or_else(reg); + let config = aws_config::from_env().region(region_provider).load().await; + let new_client = Client::new(&config); + + let resp = new_client.describe_instance_status().send().await; + + println!("Instances in region {}:", reg); println!(); + + for status in resp.unwrap().instance_statuses() { + println!( + " Events scheduled for instance ID: {}", + status.instance_id().unwrap_or_default() + ); + for event in status.events() { + println!(" Event ID: {}", event.instance_event_id().unwrap()); + println!(" Description: {}", event.description().unwrap()); + println!(" Event code: {}", event.code().unwrap().as_ref()); + println!(); + } + } } + + Ok(()) + } + Err(err) => { + println!("Error: {:?}", err); + Err(err.into()) } } - Ok(()) + // let result = resp?; + + } pub async fn enable_monitoring(client: &Client, id: &str) -> Result<(), Error> { - client.monitor_instances().instance_ids(id).send().await?; - - println!("Enabled monitoring"); + let res = client.monitor_instances().instance_ids(id).send().await; + match res { + Ok(result) =>{ + println!("Enabled monitoring: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Monitoring failed: {:?}", e); + Err(e.into()) + } + } - Ok(()) } pub async fn reboot_instance(client: &Client, id: &str) -> Result<(), Error> { - client.reboot_instances().instance_ids(id).send().await?; - - println!("Rebooted instance."); - Ok(()) + let res = client.reboot_instances().instance_ids(id).send().await; + match res { + Ok(result) =>{ + println!("Enabled monitoring: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error rebooting instance: {:?}", e); + Err(e.into()) + } + } } pub async fn start_instance(client: &Client, id: &str) -> Result<(), Error> { - client.start_instances().instance_ids(id).send().await?; - - println!("Started instance."); - - Ok(()) + let res = client.start_instances().instance_ids(id).send().await; + match res { + Ok(result) =>{ + println!("Enabled monitoring: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error rebooting instance: {:?}", e); + Err(e.into()) + } + } } pub async fn stop_instance(client: &Client, id: &str) -> Result<(), Error> { - client.stop_instances().instance_ids(id).send().await?; - - println!("Stopped instance."); - - Ok(()) + let res = client.stop_instances().instance_ids(id).send().await; + match res { + Ok(result) =>{ + println!("Enabled monitoring: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error rebooting instance: {:?}", e); + Err(e.into()) + } + } } -// fn mock_client() -> Client { -// // Create a mock client for testing purposes -// Client::new(&aws_config::load_from_env().await) -// } - -// fn mock_run_instances_output() -> RunInstancesOutput { -// // Create a mock RunInstancesOutput for testing purposes -// RunInstancesOutput::builder() -// .instances( -// std::iter::once(aws_sdk_ec2::output::Instance::builder() -// .instance_id("mock-instance-id") -// .build()) -// .collect(), -// ) -// .build() -// } - -// fn mock_create_tags_output() -> CreateTagsOutput { -// // Create a mock CreateTagsOutput for testing purposes -// CreateTagsOutput::builder().build() -// } - - -// #[cfg(test)] - - -// #[test] -// fn test_create_instance_success() { -// let client = mock_client(); -// let ami_id = "mock-ami-id"; - -// // Mock the run_instances method -// let mut run_instances_mock = client.run_instances().image_id(ami_id); -// run_instances_mock = run_instances_mock -// .instance_type(InstanceType::T1Micro) -// .min_count(1) -// .max_count(1) -// .send() -// .mocked(|_, _| Ok(mock_run_instances_output())); - -// // Mock the create_tags method -// let mut create_tags_mock = client.create_tags(); -// create_tags_mock = create_tags_mock -// .resources("mock-instance-id") -// .tags( -// Tag::builder() -// .key("Name") -// .value("From SDK Examples") -// .build(), -// ) -// .send() -// .mocked(|_, _| Ok(mock_create_tags_output())); - -// let result = create_instance(&client, ami_id).unwrap(); -// assert!(result.is_ok()); -// } - -// #[test] -// #[should_panic(expected = "No instances created.")] -// fn test_create_instance_no_instances_created() { -// let client = mock_client(); -// let ami_id = "mock-ami-id"; - -// // Mock the run_instances method to return an empty list of instances -// let mut run_instances_mock = client.run_instances().image_id(ami_id); -// run_instances_mock = run_instances_mock -// .instance_type(InstanceType::T1Micro) -// .min_count(1) -// .max_count(1) -// .send() -// .mocked(|_, _| Ok(RunInstancesOutput::builder().build())); - -// let _result = create_instance(&client, ami_id).unwrap(); -// } \ No newline at end of file diff --git a/rustcloud/src/aws/aws_apis/compute/aws_ecs.rs b/rustcloud/src/aws/aws_apis/compute/aws_ecs.rs index 4f95192..209d458 100644 --- a/rustcloud/src/aws/aws_apis/compute/aws_ecs.rs +++ b/rustcloud/src/aws/aws_apis/compute/aws_ecs.rs @@ -4,11 +4,19 @@ use aws_sdk_ecs::types::{ClusterConfiguration, ClusterField, ClusterSetting}; use aws_sdk_ecs::{types::Tag, Client, Error}; -pub async fn create_cluster(client: &Client, name: &String, tags: Option>, settings : ClusterSetting,configuration : ClusterConfiguration, capacity_providers: Option>) -> Result<(), Error> { - let cluster = client.create_cluster().cluster_name(name).set_tags(tags).settings(settings).configuration(configuration).set_capacity_providers(capacity_providers).send().await?; - println!("cluster created: {:?}", cluster); - - Ok(()) +pub async fn create_cluster(client: &Client, name: &String, tags: Option>, settings : Option>,configuration : ClusterConfiguration, capacity_providers: Option>) -> Result<(), Error> { + println!("{name}"); + let res = client.create_cluster().cluster_name(name).set_tags(tags).set_settings(settings).configuration(configuration).set_capacity_providers(capacity_providers).send().await; + match res { + Ok(result) =>{ + println!("Created: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error: {:?}", e); + Err(e.into()) + } + } } @@ -17,45 +25,70 @@ pub async fn delete_cluster( client: &Client, name: &String, ) -> Result<(), Error> { - let cluster_deleted = client.delete_cluster().cluster(name).send().await?; - println!("cluster deleted: {:?}", cluster_deleted); - - Ok(()) + let res = client.delete_cluster().cluster(name).send().await; + match res { + Ok(result) =>{ + println!("Deleted : {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } pub async fn describe_cluster(client: &Client, clusters: Option>, include:Option>) -> Result<(), Error> { - let res = client.describe_clusters().set_clusters(clusters).set_include(include).send().await?; - - let clusters = res.clusters(); - println!("Found {} clusters:", clusters.len()); - for cluster in clusters { - println!(" {}", cluster.cluster_name().unwrap()); - } - Ok(()) + let res = client.describe_clusters().set_clusters(clusters).set_include(include).send().await; + match res { + Ok(result) =>{ + let clusters = result.clusters(); + println!("Found {} clusters:", clusters.len()); + for cluster in clusters { + println!(" {}", cluster.cluster_name().unwrap()); + } + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } pub async fn show_clusters(client: &aws_sdk_ecs::Client, max_results: Option) -> Result<(), Error> { - let resp = client.list_clusters().set_max_results(max_results).send().await?; - - let cluster_arns = resp.cluster_arns(); - println!("Found {} clusters:", cluster_arns.len()); - - let clusters = client - .describe_clusters() - .set_clusters(Some(cluster_arns.into())) - .send() - .await?; - - for cluster in clusters.clusters() { - println!(" ARN: {}", cluster.cluster_arn().unwrap()); - println!(" Name: {}", cluster.cluster_name().unwrap()); + let res = client.list_clusters().set_max_results(max_results).send().await; + match res { + Ok(result) =>{ + let cluster_arns = result.cluster_arns(); + println!("Found {} clusters:", cluster_arns.len()); + + let clusters = client + .describe_clusters() + .set_clusters(Some(cluster_arns.into())) + .send() + .await; + + if clusters.is_err() { + println!("Error: {:?}", clusters.err()); + return Ok(()); + } + let describe_cluster_result = clusters?; + for cluster in describe_cluster_result.clusters() { + println!(" ARN: {}", cluster.cluster_arn().unwrap()); + println!(" Name: {}", cluster.cluster_name().unwrap()); + } + Ok(()) + } + Err(e) => { + println!("Error: {:?}", e); + Err(e.into()) + } } - - Ok(()) } diff --git a/rustcloud/src/aws/aws_apis/compute/aws_eks.rs b/rustcloud/src/aws/aws_apis/compute/aws_eks.rs index a1fa9af..af1babc 100644 --- a/rustcloud/src/aws/aws_apis/compute/aws_eks.rs +++ b/rustcloud/src/aws/aws_apis/compute/aws_eks.rs @@ -8,11 +8,10 @@ use aws_sdk_eks::types::{AmiTypes, CapacityTypes, KubernetesNetworkConfigRequest -#[tokio::main] -#[allow(clippy::result_large_err)] -pub async fn create_cluster(client: &Client, cluster_name: String,_subnet_id: Vec, version: Option, role_arn: Option, resources_vpc_config: Option, kubernetes_network_config: Option ) -> Result<(), Error> { + +pub async fn create_cluster(client: &Client, cluster_name: String, version: Option, role_arn: Option, resources_vpc_config: Option, kubernetes_network_config: Option ) -> Result<(), Error> { - let cluster = client + let res = client .create_cluster() .name(cluster_name) .set_role_arn(role_arn) @@ -20,17 +19,25 @@ pub async fn create_cluster(client: &Client, cluster_name: String,_subnet_id: Ve .set_resources_vpc_config(resources_vpc_config) .set_kubernetes_network_config(kubernetes_network_config) .send() - .await?; - println!("cluster created: {:?}", cluster); - Ok(()) - // return cluster; + .await; + match res { + Ok(result) =>{ + println!("cluster created: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } + } pub async fn create_node_group(client: &Client, cluster_name: String, nodegroup_name: String, disk_size: Option, scaling_config: Option, subnets: Option>, instance_types: Option>, ami_type: Option, remote_access: Option,node_role: Option, labels: Option>,taints: Option>,tags: Option>, client_request_token: Option, launch_template: Option,update_config: Option,capacity_type: Option,version: Option,release_version: Option ) -> Result<(), Error> { - let node_group = client.create_nodegroup() + let resp = client.create_nodegroup() .cluster_name(cluster_name) .nodegroup_name(nodegroup_name) .set_disk_size(disk_size) @@ -50,79 +57,142 @@ pub async fn create_node_group(client: &Client, cluster_name: String, nodegroup_ .set_launch_template(launch_template) .set_release_version(release_version) .send() - .await?; - - println!("nodegroup created successfully: {:?}", node_group); - Ok(()) + .await; + match resp { + Ok(result) =>{ + println!("nodegroup created successfully: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } + pub async fn delete_nodegroup(client: &Client, cluster_name: String, nodegroup_name: String) -> Result<(), Error> { - let nodegroup_deleted = client.delete_nodegroup().cluster_name(cluster_name).nodegroup_name(nodegroup_name).send().await?; - println!("nodegroup deleted: {:?}", nodegroup_deleted); - - Ok(()) + let resp = client.delete_nodegroup().cluster_name(cluster_name).nodegroup_name(nodegroup_name).send().await; + match resp { + Ok(result) =>{ + + println!("nodegroup deleted: {:?}", result); + + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } pub async fn describe_cluster(client: &Client, name: String) -> Result<(), Error> { - let cluster = client.describe_cluster().name(name).send().await?; - println!("cluster: {:?}", cluster); - Ok(()) + let resp = client.describe_cluster().name(name).send().await; + match resp { + Ok(result) =>{ + println!("cluster: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } pub async fn describe_nodegroup(client: &Client, cluster_name: String, nodegroup_name: String) -> Result<(), Error> { - let cluster = client.describe_nodegroup().cluster_name(cluster_name).nodegroup_name(nodegroup_name).send().await?; - println!("nodegroup: {:?}", cluster); - Ok(()) - + let resp = client.describe_nodegroup().cluster_name(cluster_name).nodegroup_name(nodegroup_name).send().await; + match resp { + Ok(result) =>{ + println!("nodegroup: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } -pub async fn delete_cluster(client: &Client, cluster_name: &str) -> Result<(), DeleteClusterError> { - let cluster_deleted = client.delete_cluster().name(cluster_name).send().await; - println!("cluster deleted: {:?}", cluster_deleted); - Ok(()) +pub async fn delete_cluster(client: &Client, cluster_name: &str) -> Result<(), Error> { + let resp = client.delete_cluster().name(cluster_name).send().await; + match resp { + Ok(result) =>{ + println!("cluster deleted: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } pub async fn list_clusters(client: &Client, max_results: Option, include: Option>) -> Result<(), Error> { - let resp = client.list_clusters().set_max_results(max_results).set_include(include).send().await?; - let clusters = resp.clusters(); - // ListClustersOutput - println!("Found {} clusters:", clusters.len()); - - for cluster in clusters { - println!(" {}", cluster); + let resp = client.list_clusters().set_max_results(max_results).set_include(include).send().await; + match resp { + Ok(result) =>{ + let clusters = result.clusters(); + // ListClustersOutput + println!("Found {} clusters:", clusters.len()); + + for cluster in clusters { + println!(" {}", cluster); + } + + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } } - - Ok(()) } pub async fn list_nodegroups(client: &Client, cluster_name: String, max_results: Option) -> Result<(), Error> { - let resp = client.list_nodegroups().cluster_name(cluster_name).set_max_results(max_results).send().await?; - let nodegroups = resp.nodegroups(); - // ListClustersOutput - println!("Found {} nodegroups:", nodegroups.len()); - - for nodegroup in nodegroups { - println!(" {}", nodegroup); + let resp = client.list_nodegroups().cluster_name(cluster_name).set_max_results(max_results).send().await; + match resp { + Ok(result) =>{ + let nodegroups = result.nodegroups(); + // ListClustersOutput + println!("Found {} nodegroups:", nodegroups.len()); + + for nodegroup in nodegroups { + println!(" {}", nodegroup); + } + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } } - - Ok(()) } pub async fn update_tags(client: &Client, resource_arn: String, tags: Option>) -> Result<(), Error> { - let update_tags = client.tag_resource().resource_arn(resource_arn).set_tags(tags).send().await?; - println!("tags updated: {:?}", update_tags); - Ok(()) + let resp = client.tag_resource().resource_arn(resource_arn).set_tags(tags).send().await; + match resp { + Ok(result) =>{ + println!("tags updated: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } pub async fn update_config(client: &Client, name: String, resources_vpc_config: Option, logging: Option, client_request_token: Option, access_config: Option) -> Result<(), Error> { - let update_config = + let resp = client .update_cluster_config() .name(name) @@ -130,13 +200,16 @@ pub async fn update_config(client: &Client, name: String, resources_vpc_config: .set_logging(logging) .set_client_request_token(client_request_token) .set_access_config(access_config) - .send().await?; - - println!("config updated: {:?}", update_config); - - Ok(()) -} - - - - + .send().await; + match resp { + Ok(result) =>{ + println!("config updated: {:?}", result); + + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } +} \ No newline at end of file diff --git a/rustcloud/src/aws/aws_apis/compute/aws_paas.rs b/rustcloud/src/aws/aws_apis/compute/aws_paas.rs deleted file mode 100644 index e69de29..0000000 diff --git a/rustcloud/src/aws/aws_apis/database/aws_dynamodb.rs b/rustcloud/src/aws/aws_apis/database/aws_dynamodb.rs index acc14fa..5379e75 100644 --- a/rustcloud/src/aws/aws_apis/database/aws_dynamodb.rs +++ b/rustcloud/src/aws/aws_apis/database/aws_dynamodb.rs @@ -5,47 +5,81 @@ use tokio; use aws_sdk_dynamodb::{types::{AttributeDefinition, AttributeValue, BillingMode, Condition, ConditionalOperator, ExpectedAttributeValue, GlobalSecondaryIndex, KeySchemaElement, LocalSecondaryIndex, OnDemandThroughput, ProvisionedThroughput, ReturnConsumedCapacity, ReturnItemCollectionMetrics, ReturnValue, ReturnValuesOnConditionCheckFailure, Select, SseSpecification, StreamSpecification, TableClass, Tag}, Client, Error}; -#[tokio::main] -#[allow(clippy::result_large_err)] -pub async fn create_table(client : &Client, attribute_definitions:AttributeDefinition,table_name: String,key_schema:KeySchemaElement,local_secondary_indexes: LocalSecondaryIndex,global_secondary_index: GlobalSecondaryIndex,billing_mode: BillingMode,provisioned_throughput :ProvisionedThroughput,stream_specification :StreamSpecification,sse_specification :SseSpecification,tags :Option>, +pub async fn create_table(client : &Client, attribute_definitions:AttributeDefinition,table_name: String,key_schema:KeySchemaElement,local_secondary_indexes: Option>,global_secondary_index: Option>,billing_mode: BillingMode,provisioned_throughput :ProvisionedThroughput,stream_specification :Option,sse_specification :Option,tags :Option>, table_class: TableClass,deletion_protection_enabled: Option,resource_policy: Option,on_demand_throughput: Option) -> Result<(), Error> { - let table = client.create_table().attribute_definitions(attribute_definitions).table_name(table_name).key_schema(key_schema).local_secondary_indexes(local_secondary_indexes).global_secondary_indexes(global_secondary_index).billing_mode(billing_mode).provisioned_throughput(provisioned_throughput).stream_specification(stream_specification).sse_specification(sse_specification).set_tags(tags).table_class(table_class).set_deletion_protection_enabled(deletion_protection_enabled).set_resource_policy(resource_policy).set_on_demand_throughput(on_demand_throughput).send().await?; + let resp = client.create_table().attribute_definitions(attribute_definitions).table_name(table_name).key_schema(key_schema).set_local_secondary_indexes(local_secondary_indexes).set_global_secondary_indexes(global_secondary_index).billing_mode(billing_mode).provisioned_throughput(provisioned_throughput).set_stream_specification(stream_specification).set_sse_specification(sse_specification).set_tags(tags).table_class(table_class).set_deletion_protection_enabled(deletion_protection_enabled).set_resource_policy(resource_policy).set_on_demand_throughput(on_demand_throughput).send().await; + + match resp { + Ok(result) =>{ + println!("table created: {:?}", result); + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } - println!("table created: {:?}", table); - - Ok(()) } pub async fn delete_item(client: &Client, table_name: String, key: Option>, expected: Option>, conditional_operator: Option, return_values: Option, return_consumed_capacity: Option, return_item_collection_metrics: Option, condition_expression: Option, expression_attribute_names: Option>, expression_attribute_values: Option>,return_values_on_condition_check_failure: Option) -> Result<(), Error> { - let delete_item = client.delete_item().table_name(table_name).set_key(key).set_expected(expected).set_conditional_operator(conditional_operator).set_return_values(return_values).set_return_consumed_capacity(return_consumed_capacity).set_return_item_collection_metrics(return_item_collection_metrics).set_condition_expression(condition_expression).set_expression_attribute_names(expression_attribute_names).set_return_values_on_condition_check_failure(return_values_on_condition_check_failure).set_expression_attribute_values(expression_attribute_values).send().await?; - - println!("item deleted: {:?}", delete_item); - - - Ok(()) + let resp = client.delete_item().table_name(table_name).set_key(key).set_expected(expected).set_conditional_operator(conditional_operator).set_return_values(return_values).set_return_consumed_capacity(return_consumed_capacity).set_return_item_collection_metrics(return_item_collection_metrics).set_condition_expression(condition_expression).set_expression_attribute_names(expression_attribute_names).set_return_values_on_condition_check_failure(return_values_on_condition_check_failure).set_expression_attribute_values(expression_attribute_values).send().await; + + match resp { + Ok(result) =>{ + + println!("item deleted: {:?}", result); + + + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } } pub async fn delete_table(client: &Client, table_name: String) -> Result<(), Error> { - let delete_table = client.delete_table().table_name(table_name).send().await?; + let resp = client.delete_table().table_name(table_name).send().await; - println!("table deleted: {:?}", delete_table); + match resp { + Ok(result) =>{ + + println!("table deleted: {:?}", result); + + Ok(()) + } + Err(e) => { + println!("Error : {:?}", e); + Err(e.into()) + } + } - Ok(()) } pub async fn query(client: &Client, table_name: String, index_name: Option, select: Option