typescript - 允许从 ECS 连接到现有的 RDS 数据库?

标签 typescript amazon-web-services aws-cdk

我目前正在尝试识别现有的 MySQL 实例,并且我想让我的 ECS 部署能够连接到它。

目前的进展如下:

    const rdsPrimaryDatabase = rds.DatabaseInstance.fromDatabaseInstanceAttributes(this, 'ApplicationReadWrite', {
      instanceEndpointAddress: "application_database_ewqqqrqw.eu-west-1.rds.amazonaws.com", port: 3305, securityGroups: [],
      instanceIdentifier: 'application_database'
    });

    const securityGroup = new ec2.SecurityGroup(this, 'ApplicationEcsSecurityGroup', {
      vpc: vpc,
      allowAllOutbound: true,
      securityGroupName: 'ApplicationEcsSecurityGroup',
    })

    securityGroup.connections.allowTo(rdsPrimaryDatabase, 3306, 'Primary Database')

以上当前导致以下错误,与最后一行相关:

    Argument of type 'IDatabaseInstance' is not assignable to parameter of type 'IConnectable'.
    The types of 'connections.defaultPort' are incompatible between these types.

这个错误是可以理解的,但我不确定如何克服这个问题 - 而且我不太确定我的做法是否正确。

感谢任何帮助。

最佳答案

尝试导入数据库实例的安全组,而不是导入数据库实例。

ISecurityGroup databaseSecurityGroup SecurityGroup.FromSecurityGroupId(scope, "ImportedDatabaseSecurityGroup", securityGroupId, new SecurityGroupImportOptions());

var fargateServiceSecurityGroup = new SecurityGroup(this, "FargateServiceSecurityGroup", new SecurityGroupProps());

databaseSecurityGroup.Connections.AllowFrom(fargateServiceSecurityGroup, Port.AllTcp(), "Allow from fargate security group");

关于typescript - 允许从 ECS 连接到现有的 RDS 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68314584/

相关文章:

typescript 找不到本地链接的模块?

angular - 从 Angular 2 中的子组件更新父组件属性

eclipse - Angular2 Eclipse : HTML editor in Eclipse Oxygen shows errors from TypeScript

typescript - 如何使用 Typescript 的 CDK 配置发送(apigateway)和获取(lambda)请求查询参数

aws-cloudformation - 安装 yum 软件包时 AWS CDK CloudFormationInit 超时

typescript - 你如何从 typescript AST 中获得推断类型?

python - AWS Glue psycopg2 安装

amazon-web-services - 如何使用 aws iot 规则引擎更新 dynamodb 的多列

java - 亚马逊 AWS KMS + Gradle : NoClassDefFoundError

amazon-web-services - 从 AWS CDK 中 SSM 参数名称中的堆栈参数命名 SSM 参数