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

查看:16
本文介绍了如何从 Cloud Formation 获取弹性容器存储库 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 都支持它.

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.

但是,您可以解决这个问题,因为存储库 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}"

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

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