One line create repository with policy in AWS ECR

The Problem: AWS EC2 Container Registry (aka ECR) uses ACL policy per each repository to specify who has what access to it. So to create new repository one must not forget to add it after creation. Problem is the web interface doesn’t allow to copy-paste the policy but forces to to use the policy creator form, which is highly annoying when one need to create lot of repositories at once.

Fortunately AWS CLI interface provides command for that, but again it is separated to two stages create-repository and set-repository-policy. Here is the way how I made my life easier with some simple shell scripting:

First create policy in the ECR interface and copy its JSON from there. Save the json in file in your convenient location.

Open your shell and create temporary function:

Then run to create each repository: