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

add EKS & example (#553)

* add EKS & example

* Fix clippy error & add const fn while I'm at it
parent f9311e9b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ impl Region {
    pub fn new(region: impl Into<Cow<'static, str>>) -> Self {
        Self(region.into())
    }
    pub const fn from_static(region: &'static str) -> Self {
        Self(Cow::Borrowed(region))
    }
}

/// Provide a [`Region`](Region) to use with AWS requests
+2 −1
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ val tier1Services = setOf(
    "sns",
    "sqs",
    "ssm",
    "sts"
    "sts",
    "eks"
)

private val disableServices = setOf("transcribestreaming")
+11 −0
Original line number Diff line number Diff line
[package]
name = "eks"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2018"

[dependencies]
structopt = { version = "0.3", default-features = false }
tokio = { version = "1", features = ["full"]}
aws-types = { path = "../../build/aws-sdk/aws-types" }
aws-sdk-eks = { path = "../../build/aws-sdk/eks" }
+63 −0
Original line number Diff line number Diff line
use aws_sdk_eks::model::VpcConfigRequest;
use aws_sdk_eks::Region;
use aws_types::region;
use aws_types::region::ProvideRegion;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    /// The region
    #[structopt(short, long)]
    region: Option<String>,

    #[structopt(short, long)]
    cluster_name: String,

    /// Role ARN for the cluster
    /// To create a role-arn:
    ///
    /// 1. Follow instructions to create an IAM role:
    /// https://docs.aws.amazon.com/eks/latest/userguide/service_IAM_role.html
    ///
    /// 2. Copy role arn
    #[structopt(long)]
    role_arn: String,

    /// subnet id
    ///
    /// At least two subnet ids must be specified. The subnet ids must be in two separate AZs
    #[structopt(short, long)]
    subnet_id: Vec<String>,
}

#[tokio::main]
async fn main() -> Result<(), aws_sdk_eks::Error> {
    let Opt {
        region,
        cluster_name,
        role_arn,
        subnet_id,
    } = Opt::from_args();
    let region = region
        .map(Region::new)
        .or_else(|| region::default_provider().region())
        .unwrap_or_else(|| Region::from_static("us-west-2"));
    let conf = aws_sdk_eks::Config::builder().region(region).build();
    let client = aws_sdk_eks::Client::from_conf(conf);
    let cluster = client
        .create_cluster()
        .name(&cluster_name)
        .role_arn(role_arn)
        .resources_vpc_config(
            VpcConfigRequest::builder()
                .set_subnet_ids(Some(subnet_id))
                .build(),
        )
        .send()
        .await?;
    println!("cluster created: {:?}", cluster);

    let cluster_deleted = client.delete_cluster().name(&cluster_name).send().await?;
    println!("cluster deleted: {:?}", cluster_deleted);
    Ok(())
}