How to get Elastic Container Repository URI from Cloud Formation?

后端 未结 2 1473
予麋鹿
予麋鹿 2021-01-01 22:30

I\'m trying to create an Elastic Container Service (ECS) setup from Cloud Formation.

However I don\'t want the ECS repository to have the ugly autogenerated URI:

相关标签:
2条回答
  • 2021-01-01 22:52
    HostName: !Join [ ".", [ !Ref "AWS::AccountId", "dkr.ecr", !Ref "AWS::Region", !Join [ "/", [ "amazonaws.com", !Ref "dockerrepocompanycom" ] ] ] ]
    

    A more concise way is as follows:

    HostName: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${dockerrepocompanycom}"
    

    (adding as separate answer because I lack reputation points to comment on previous answer)

    0 讨论(0)
  • 2021-01-01 23:02

    This is kind of silly, but in the end it seems you cannot refer to the URI of an ECR because Cloud Formation doesn't support it.

    There's no attribute for the URI, even though funnily enough their Ruby SDK does support it and even the third-party, cross-cloud Terraform supports it.

    However, you can hack around this because the repository URI is stable, it doesn't contain any random part, so you can compose the URI from things you already have:

    HostName: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${dockerrepocompanycom}"
    

    or for the less cool, old-school version:

    HostName: !Join [ ".", [ !Ref "AWS::AccountId", "dkr.ecr", !Ref "AWS::Region", !Join [ "/", [ "amazonaws.com", !Ref "dockerrepocompanycom" ] ] ] ]
    

    Full working configuration for creating the S3 bucket:

       s3dockerrepo1redirect:
        Type: AWS::S3::Bucket
        Properties:
            BucketName: "docker-repo.company.com"
            WebsiteConfiguration:
                RedirectAllRequestsTo:
                   HostName: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${dockerrepocompanycom}"
    
    0 讨论(0)
提交回复
热议问题