简体   繁体   English

AWS CDK 引用 ECR 上的现有映像

[英]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.

相关问题 AWS CDK:如何从 ECR 存储库上的现有 Docker 映像创建 Lambda function? - AWS CDK: How to create a Lambda function from an existing Docker image on ECR repo? 使用Python Docker API从AWS ECR获取Image哈希 - Using the Python Docker API to get an Image hash from an AWS ECR 使用 Python Lambda 函数的 AWS ECR 图像标签 - AWS ECR Image Tags using Python Lambda Function 如何将来自 AWS ECR 的私有镜像与 Airflow 的 DockerOperator 一起使用? - How to use a private image from AWS ECR with Airflow's DockerOperator? 在创建粘合表时使用 aws-cdk 中的现有数据库 - Using existing database in aws-cdk while creating a glue table 如何使用 Python AWS-CDK 将现有资源添加到堆栈? - How to add an existing resource to stack using Python AWS-CDK? AWS CDK 解析错误:无法使用循环引用解析 object 树 - AWS CDK Resolution error: Unable to resolve object tree with circular reference 自动化 AWS ECR 扫描 - Automate AWS ECR scanning 如何在 AWS CDK 中为 Python 覆盖 aws_cdk.core.LegacyStackSynthesizer.add_docker_image_asset - How to override aws_cdk.core.LegacyStackSynthesizer.add_docker_image_asset in AWS CDK for Python AWS CDK 并在现有 ALB 上创建 ECS/Fargate 服务。 使用现有的监听器? - AWS CDK and creating ECS/Fargate Service on existing ALB. Use existing listener?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM