[英]AWS CDK reference existing image on ECR
New to AWS CDK and I'm trying to create a load balanced fargate service with the construct ApplicationLoadBalancedFargateService. AWS CDK 的新手,我正在尝试使用构造 ApplicationLoadBalancedFargateService 创建负载平衡的 Fargate 服务。
I have an existing image on ECR that I would like to reference and use.我想参考和使用 ECR 上的现有图像。 I've found the ecs.ContainerImage.from_ecr_repository function, which I believe is what I should use in this case.
我找到了 ecs.ContainerImage.from_ecr_repository 函数,我相信在这种情况下我应该使用它。 However, this function takes an IRepository as a parameter and I cannot find anything under aws_ecr.IRepository or aws_ecr.Repository to reference a pre-existing image.
但是,此函数将 IRepository 作为参数,我在 aws_ecr.IRepository 或 aws_ecr.Repository 下找不到任何内容来引用预先存在的图像。 These constructs all seem to be for making a new repository.
这些构造似乎都是为了创建一个新的存储库。
Anyone know what I should be using to get the IRepository object for an existing repo?任何人都知道我应该使用什么来获取现有仓库的 IRepository 对象? Is this just not typically done this way?
这只是通常不这样做吗?
Code is below.代码如下。 Thanks in Advance.
提前致谢。
from aws_cdk import (
# Duration,
Stack,
# aws_sqs as sqs,
)
from constructs import Construct
from aws_cdk import (aws_ec2 as ec2, aws_ecs as ecs,
aws_ecs_patterns as ecs_patterns,
aws_route53,aws_certificatemanager,
aws_ecr)
class NewStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
_repo = aws_ecr.Repository(self, 'id1', repository_uri = repo_uri)
vpc = ec2.Vpc(self, "applications", max_azs=3) # default is all AZs in region
cluster = ecs.Cluster(self, "id2", vpc=vpc)
hosted_zone = aws_route53.HostedZone.from_lookup(self,
'id3',
domain_name = 'domain'
)
certificate = aws_certificatemanager.Certificate.from_certificate_arn(self,
id4,
'cert_arn'
)
image = ecs.ContainerImage.from_ecr_repository(self, _repo)
ecs_patterns.ApplicationLoadBalancedFargateService(self, "id5",
cluster=cluster, # Required
cpu=512, # Default is 256
desired_count=2, # Default is 1
task_image_options=ecs_patterns.ApplicationLoadBalancedTaskImageOptions(
image = image,
container_port=8000),
memory_limit_mib=2048, # Default is 512
public_load_balancer=True,
domain_name = 'domain_name',
domain_zone = hosted_zone,
certificate = certificate,
redirect_http = True)
您正在寻找from_repository_attributes()以从现有 ECR 存储库创建IRepository
实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.