Skip to main content
Version: Torizon OS 7.x.y

AWS Elastic Container Registry (ECR)

Introduction

Amazon Elastic Container Registry (ECR) is the Docker container registry solution from AWS.

In this article, we will use the TorizonCore Builder Tool to authenticate and pre-provide the target devices with a private container image hosted in ECR. This guide assumes you have followed the steps in the Private Registry Introduction and Prerequisites.

Disclaimer

This guide offers a general guideline for further development and, therefore, should always be adapted to your specific use case.

In real-world scenarios, ensure you set up the appropriate access control, authentication and permissions.

Set Up the AWS Cloud Environment

caution

Please check Private repository policies and policy examples to find the set of permissions that better fits your specific application.

  1. Create a private registry. For more information, see Getting started with Amazon ECR.

  2. Create two IAM users:

    • One with full registry management permission for the host machine.
    • Another with read-only permission for the deployed devices (in this guide, we are using AmazonEC2ContainerRegistryReadOnly).

    Remember to take note of the credentials. It will be used to authenticate the user.

  3. Install the AWS CLI. In this guide, installing the AWS CLI on the board is not required. For more information, see Getting started with AWS CLI.

Get the Authentication Tokens (Host Machine)

tip

In this guide, we will use an authorization token. For other authentication methods, see Private registry authentication.

To get the authentication tokens on the host machine, proceed as follows:

  1. In the host machine, log in with the host machine AWS Access Key ID and AWS Secret Access Key.

    $ aws configure
  2. To save the credentials to be used by docker, run the docker login command.

    • The <username> is "AWS".

    • The <registry-url> looks like <aws_account_id>.dkr.ecr.<region>.amazonaws.com.

    $ aws ecr get-login-password | docker login --username <username> --password-stdin <registry-url>
  3. Push the image to AWS. The docker push command should be working normally by default, using the host machine Access Keys. For more details, see docker push in ECR.

Push the AWS Docker-Compose to Torizon Cloud Using TCB

tip

It is a best practice to canonicalize the version of the docker-compose file before pushing it to Torizon OTA.

To use torizoncore-builder platform push with private repositories, we need to authenticate using the following flag:

--login-to <repository-url> <username> <password>

To get the <password>:

  1. Login using the deployed device AWS Access Key ID and AWS Secret Access Key in the host machine.

    $ aws configure
  2. Run the get-login-password command.

    $ aws ecr get-login-password 
  3. Push the docker-compose file to Torizon Cloud. If you are missing <path-to-credentials.zip>, please check the prerequisites.

    $ torizoncore-builder platform push \
    --credentials <path-to-credentials.zip> \
    --login-to <registry-url> <username> <password> \
    --canonicalize \
    <path-to-dockercompose.yml>

Get the Authentication Tokens in AWS (Deployed Device)

danger

The authentication token from AWS is short-lived and expires after 12 hours.

  1. Run the following command to save the authentication token to /etc/docker/config.json.

    $ aws ecr get-login-password | docker --config /etc/docker login --username <username> --password-stdin <registry-url>
  2. Copy the authentication file (/etc/docker/config.json) from the host machine to the target device and it should be ready to receive an update from Torizon Cloud.

    This enables that single device to receive an OTA update. Scaling is really simple with torizoncore-builder and Torizon Cloud, check the section on how to enable multiple devices.



Send Feedback!