From 69ab835ebcc7efb9162741e3f0f04f22d1ed4708 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 19 Jul 2019 15:37:17 +0100 Subject: rename pipelineaws to setupawspipeline --- pipelineaws/main.go | 72 ------------------------------------------------ setupawspipeline/main.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 pipelineaws/main.go create mode 100644 setupawspipeline/main.go diff --git a/pipelineaws/main.go b/pipelineaws/main.go deleted file mode 100644 index 26f1088..0000000 --- a/pipelineaws/main.go +++ /dev/null @@ -1,72 +0,0 @@ -package main - -import ( - "log" - "os" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/s3" - "github.com/aws/aws-sdk-go/service/sqs" -) - -func main() { - if len(os.Args) != 1 { - log.Fatal("Usage: pipelineaws\n\nSets up necessary S3 buckets and SQS queues for our AWS pipeline\n") - } - - sess, err := session.NewSession(&aws.Config{ - Region: aws.String("eu-west-2"), - }) - if err != nil { - log.Fatalf("Error: failed to set up aws session: %v\n", err) - } - s3svc := s3.New(sess) - sqssvc := sqs.New(sess) - - prefix := "rescribe" - buckets := []string{"inprogress", "done"} - queues := []string{"preprocess", "ocr", "analyse"} - - for _, bucket := range buckets { - bname := prefix + bucket - log.Printf("Creating bucket %s\n", bname) - _, err = s3svc.CreateBucket(&s3.CreateBucketInput{ - Bucket: aws.String(bname), - }) - if err != nil { - aerr, ok := err.(awserr.Error) - if ok && (aerr.Code() == s3.ErrCodeBucketAlreadyExists || aerr.Code() == s3.ErrCodeBucketAlreadyOwnedByYou) { - log.Printf("Bucket %s already exists\n", bname) - } else { - log.Fatalf("Error creating bucket %s: %v\n", bname, err) - } - } - } - - for _, queue := range queues { - qname := prefix + queue - log.Printf("Creating queue %s\n", qname) - _, err = sqssvc.CreateQueue(&sqs.CreateQueueInput{ - QueueName: aws.String(qname), - Attributes: map[string]*string{ - "VisibilityTimeout": aws.String("120"), // 2 minutes - "MessageRetentionPeriod": aws.String("1209600"), // 14 days; max allowed by sqs - "ReceiveMessageWaitTimeSeconds": aws.String("20"), - }, - }) - if err != nil { - aerr, ok := err.(awserr.Error) - // Note the QueueAlreadyExists code is only emitted if an existing queue - // has different attributes than the one that was being created. SQS just - // quietly ignores the CreateQueue request if it is identical to an - // existing queue. - if ok && aerr.Code() == sqs.ErrCodeQueueNameExists { - log.Fatalf("Error: Queue %s already exists but has different attributes\n", qname) - } else { - log.Fatalf("Error creating queue %s: %v\n", qname, err) - } - } - } -} diff --git a/setupawspipeline/main.go b/setupawspipeline/main.go new file mode 100644 index 0000000..2120b5b --- /dev/null +++ b/setupawspipeline/main.go @@ -0,0 +1,72 @@ +package main + +import ( + "log" + "os" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go/service/sqs" +) + +func main() { + if len(os.Args) != 1 { + log.Fatal("Usage: setupawspipeline\n\nSets up necessary S3 buckets and SQS queues for our AWS pipeline\n") + } + + sess, err := session.NewSession(&aws.Config{ + Region: aws.String("eu-west-2"), + }) + if err != nil { + log.Fatalf("Error: failed to set up aws session: %v\n", err) + } + s3svc := s3.New(sess) + sqssvc := sqs.New(sess) + + prefix := "rescribe" + buckets := []string{"inprogress", "done"} + queues := []string{"preprocess", "ocr", "analyse"} + + for _, bucket := range buckets { + bname := prefix + bucket + log.Printf("Creating bucket %s\n", bname) + _, err = s3svc.CreateBucket(&s3.CreateBucketInput{ + Bucket: aws.String(bname), + }) + if err != nil { + aerr, ok := err.(awserr.Error) + if ok && (aerr.Code() == s3.ErrCodeBucketAlreadyExists || aerr.Code() == s3.ErrCodeBucketAlreadyOwnedByYou) { + log.Printf("Bucket %s already exists\n", bname) + } else { + log.Fatalf("Error creating bucket %s: %v\n", bname, err) + } + } + } + + for _, queue := range queues { + qname := prefix + queue + log.Printf("Creating queue %s\n", qname) + _, err = sqssvc.CreateQueue(&sqs.CreateQueueInput{ + QueueName: aws.String(qname), + Attributes: map[string]*string{ + "VisibilityTimeout": aws.String("120"), // 2 minutes + "MessageRetentionPeriod": aws.String("1209600"), // 14 days; max allowed by sqs + "ReceiveMessageWaitTimeSeconds": aws.String("20"), + }, + }) + if err != nil { + aerr, ok := err.(awserr.Error) + // Note the QueueAlreadyExists code is only emitted if an existing queue + // has different attributes than the one that was being created. SQS just + // quietly ignores the CreateQueue request if it is identical to an + // existing queue. + if ok && aerr.Code() == sqs.ErrCodeQueueNameExists { + log.Fatalf("Error: Queue %s already exists but has different attributes\n", qname) + } else { + log.Fatalf("Error creating queue %s: %v\n", qname, err) + } + } + } +} -- cgit v1.2.1-24-ge1ad