typescript - Tillåt anslutningar från ECS till en befintlig RDS-databas?


Jag försöker för närvarande identifiera en befintlig MySQL-instans och jag vill tillåta att min ECS-distribution kan ansluta till den.

Framstegen hittills är följande:

    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')

Ovanstående resulterar för närvarande i följande fel, relaterat till den sista raden:

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

Felet är ganska förståeligt, men jag är osäker på hur jag ska övervinna det - och jag är inte heller riktigt säker på att jag gör det på rätt sätt.

All hjälp uppskattas.

Svar #1

Istället för att importera databasinstanserna, försök importera databasinstansens säkerhetsgrupp.

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");

Relaterade artiklar