Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Don't error if ECR Repository exists already
Browse files Browse the repository at this point in the history
We were returning an error if the ECR repo already exists. This shouldnt
give an error because it's not a failure. If the repo doesn't exist then
we create it, if it exists then that's fine.

Tested by deploying an ECR backed OFC installation, first time round it
creates the new repo, then after that it's not throwing an error, only
saying it already exists.

Signed-off-by: Alistair Hey <alistair@heyal.co.uk>
  • Loading branch information
Waterdrips authored and alexellis committed Apr 22, 2020
1 parent 90d3204 commit 27eb84d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions register-image/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions register-image/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package function
import (
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
"log"
"os"
"strings"
Expand Down Expand Up @@ -68,9 +69,14 @@ func Handle(req []byte) string {
output, err := client.CreateRepository(&repoReq)

if err != nil {
log.Printf("CreateRepository error: %s\n", err.Error())
os.Exit(1)
if aerr, ok := err.(awserr.Error); ok {
if aerr.Code() != ecr.ErrCodeRepositoryAlreadyExistsException {
log.Printf("CreateRepository error: %s\n", err.Error())
os.Exit(1)
}
}
return fmt.Sprintf("Repo Exists: %s", *repoReq.RepositoryName)
}

return fmt.Sprintf("Created repo: %s\n", output.String())
return fmt.Sprintf("Created the repo: %s", output.String())
}

0 comments on commit 27eb84d

Please sign in to comment.