AWS CDK 新手,我正在尝试使用构造 ApplicationLoadBalancedFargateService 创建负载平衡的 Fargate 服务。
我在 ECR 上有一个现有图像,我想参考和使用。我找到了 ecs.ContainerImage.from_ecr_repository 函数,我相信在这种情况下我应该使用它。但是,此函数采用 IRepository 作为参数,我在 aws_ecr.IRepository 或 aws_ecr.Repository 下找不到任何内容来引用预先存在的图像。这些构造似乎都是为了创建一个新的存储库。
有人知道我应该使用什么来获取现有存储库的 IRepository 对象吗?这通常不是这样做的吗?
代码如下。提前致谢。
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 …Run Code Online (Sandbox Code Playgroud) 我有以下功能get_postgres_connection。我正在尝试运行单元测试来test_get_postgres_connection_unsuccess命中异常。
def get_postgres_connection():\n \n try:\n conn = psycopg2.connect(dbname = POSTGRES_DATABASE,\n user = POSTGRES_USER,\n password = POSGRES_PASSWORD,\n host = POSTGRES_HOST,\n port =\xc2\xa0POSTGRES_PORT)\n conn.autocommit = True\n \n return conn\n \n except Exception as err:\n logging.error(\'Unable to connect to postgres db: %s\', err)\n\n\ndef test_get_postgres_connection_unsuccess(monkeypatch):\n """ tests an exception is hit if the connection to postgres is unsuccesful"""\n \n # setup\n class mock_conn:\n def __init__(self, dbname, user, password, host, port):\n raise ConnectionError(\'This fake connection did not work\')\n\n autocommit = …Run Code Online (Sandbox Code Playgroud) python ×2
amazon-ecr ×1
aws-cdk ×1
aws-fargate ×1
exception ×1
mocking ×1
postgresql ×1
pytest ×1