AWS ECR start uploaded docker image? I used packer to upload a docker image I created to my AWS ECR repository.

How can I use the AWS cli to automatically locate that image, create a new cluster, set the port rules to allow all inbound and outbound traffic and then spin up the container?
I want to automate this process so I can integrate it into packer later, as a post processor.

Can someone explain me how I can do this?

{
    "type": "docker-push",
    "ecr_login": true,
    "aws_access_key": "&lt;snip&gt;",
    "aws_secret_key": "&lt;snipe&gt;",
    "login_server": "https://&lt;snip&gt;.dkr.ecr.eu-west-1.amazonaws.com/"
}


Currently the last part of my packer script just uploads the image - now I need a way to automatically start this docker image and make sure the network traffic settings are configured correctly.
The answer depends on how you want to run the container.  There are 3 ways you could accomplish this:


Since you mentioned creating a cluster, you could create a new Kubernetes cluster and run your containers in this cluster.  AWS does support creating a cluster and managing of it via the CLI.
You can choose to run the containers as part of AWS Elastic Container Service (ECS).  This supports launching the containers via AWS Fargate (essentially a "serverless" type approach where you pay for CPU and Memory consumed) or on a standard EC2 instance.  ECS has its own CLI (separate install).  ECS will also allow you to set the ports and set inbound/outbound rules.
Finally, you can choose to use the CLI to spin up an EC2 instance and then manually or via a script start the docker containers.  However, you'd be much better off choosing one of the first two options.


Finally, AWS does have a tutorial that seems to go over exactly what you are trying to accomplish (configuring a container to run via the CLI).