I'm trying to have a script automatically create ECR repos for projects as part of the pipeline. I want to check if it already exists first, however describe-repositories returns an error instead of "nothing", and it's not caught in a try/catch .
try{
$ErrorActionPreference = "Stop"
aws ecr describe-repositories --repository-names "some-project"
}
catch {
aws ecr create-repository --repository-name "some-project"
}
Output:
An error occurred (RepositoryNotFoundException) when calling the DescribeRepositories operation: The repository with name '...' does not exist in the registry with id '...'
Is there a way to capture the error? Edit: Setting $ErrorActionPreference = "Stop" doesn't change behaviour.