如何从云形成中获取弹性容器存储库URI? [英] How to get Elastic Container Repository URI from Cloud Formation?

查看:85
本文介绍了如何从云形成中获取弹性容器存储库URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Cloud Formation创建一个弹性容器服务(ECS)设置.

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

但是我不希望ECS存储库具有丑陋的自动生成的URI:

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

111111111.dkr.ecr.us-east-1.amazonaws.com/docker-repo.company.com

但是我希望它具有漂亮而闪亮的

but instead I want it to have a nice and shiny

docker-repo.company.com

存储库本身不允许设置URI或即使是CNAME .因此,我正在尝试设置S3存储桶以重定向到存储库.但是,除非我丢失了某些内容,否则Cloud Formation不支持此功能,因为使用!Ref或!GetAtt时,我无法在AWS :: ECR :: Repository对象中查询任何内容,这将为我提供存储库URI.

The repository itself does not allow setting the URI or even a CNAME. So I'm trying to setup a S3 bucket to redirect to the repo. However unless I'm missing something, Cloud Formation doesn't support this since using !Ref or !GetAtt there's nothing I can query in the AWS::ECR::Repository object that will give me the repository URI.

我错过了什么吗?谢谢!

Am I missing something? Thanks!

推荐答案

这有点愚蠢,但最后似乎无法引用ECR的URI,因为Cloud Formation不支持它.

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.

该URI没有属性,即使他们的 Ruby SDK确实支持它甚至第三方,跨云Terraform都支持.

但是,您可以解决此问题,因为存储库URI是稳定的,它不包含任何随机部分,因此您可以根据已有的内容来组成URI:

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" ] ] ] ]

用于创建S3存储桶的完整工作配置:

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}"

这篇关于如何从云形成中获取弹性容器存储库URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆