You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/02/04 14:32:11 UTC

[GitHub] [airflow] cboden commented on issue #9707: DockerOperator AWS ECR Login Unauthorised

cboden commented on issue #9707:
URL: https://github.com/apache/airflow/issues/9707#issuecomment-773353852


   The CLI API has changed in Airflow v2. I've updated the credentials code for anyone like me who landed here trying to get ECR working, using Airflows Python library instead of subprocesses:
   
   ```python
   from airflow import settings
   from airflow.models import Connection
   
   
   def update_credentials():
       """Retrieves ECR access token and updates Airflow docker_ecr connection"""
       aws_hook = AwsHook("aws_credentials")
       credentials = aws_hook.get_credentials()
   
       ecr = boto3.client(
           'ecr',
           region_name='eu-west-2',
           aws_access_key_id=credentials.access_key,
           aws_secret_access_key=credentials.secret_key
       )
       response = ecr.get_authorization_token()
   
       username, password = base64.b64decode(
           response['authorizationData'][0]['authorizationToken']
       ).decode('utf-8').split(':')
   
       registry_url = response['authorizationData'][0]['proxyEndpoint']
   
       conn = Connection(
           conn_id="docker_ecr",
           conn_type="docker",
           host=registry_url,
           login=username,
           password=password,
       )
   
       session = settings.Session()
       session.query(Connection).filter(Connection.conn_id == "docker_ecr").delete()
       session.add(conn)
       session.commit()
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org