2
respostas

[Dúvida] cdk deploy Rds Subnet IDs are required

Estou tendo um problema ao tentar rodar o cdk deploy --parameters Rds:senha=12345678 Rds

Rds | 09:12:32 | CREATE_FAILED        | AWS::RDS::DBSubnetGroup        | Rds-pedidos/SubnetGroup/Default (RdspedidosSubnetGroupA487F029) Resource handler returned message: "Subnet IDs are required. (Service: Rds, Status Code: 400, R
equest ID: ceeef90c-872a-41d4-bb02-5c44fb8037e3)" (RequestToken: e0636217-d5ee-ea1f-ad38-f26a3cc7bb43, HandlerErrorCode: InvalidRequest)

 ❌  Rds failed: Error: The stack named Rds failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Subnet IDs are required. (Service: Rds, Status Code: 400, Re
quest ID: ceeef90c-872a-41d4-bb02-5c44fb8037e3)" (RequestToken: e0636217-d5ee-ea1f-ad38-f26a3cc7bb43, HandlerErrorCode: InvalidRequest)
    at FullCloudFormationDeployment.monitorDeployment (C:\Users\LuizGuilherme\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:467:10232)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.deployStack2 [as deployStack] (C:\Users\LuizGuilherme\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:470:180228)
    at async C:\Users\LuizGuilherme\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:470:163476

 ❌ Deployment failed: Error: The stack named Rds failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Subnet IDs are required. (Service: Rds, Status Code: 4
00, Request ID: ceeef90c-872a-41d4-bb02-5c44fb8037e3)" (RequestToken: e0636217-d5ee-ea1f-ad38-f26a3cc7bb43, HandlerErrorCode: InvalidRequest)
    at FullCloudFormationDeployment.monitorDeployment (C:\Users\LuizGuilherme\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:467:10232)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.deployStack2 [as deployStack] (C:\Users\LuizGuilherme\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:470:180228)
    at async C:\Users\LuizGuilherme\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:470:163476

The stack named Rds failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "Subnet IDs are required. (Service: Rds, Status Code: 400, Request ID: ceeef90c-872a
-41d4-bb02-5c44fb8037e3)" (RequestToken: e0636217-d5ee-ea1f-ad38-f26a3cc7bb43, HandlerErrorCode: InvalidRequest)

Fiz algumas pesquisas e tentativas mas nao consegui resolver.

Esse é o meu arquivo AluraVpcStack

package com.myorg;

import software.amazon.awscdk.Stack;
import software.amazon.awscdk.StackProps;
import software.amazon.awscdk.services.ec2.Vpc;
import software.amazon.awscdk.services.ecs.Cluster;
import software.amazon.awscdk.services.ecs.ContainerImage;
import software.amazon.awscdk.services.ecs.patterns.ApplicationLoadBalancedFargateService;
import software.amazon.awscdk.services.ecs.patterns.ApplicationLoadBalancedTaskImageOptions;
import software.constructs.Construct;

public class AluraVpcStack extends Stack {

    private Vpc vpc;
    public AluraVpcStack(final Construct scope, final String id) {
        this(scope, id, null);
    }

    public AluraVpcStack(final Construct scope, final String id, final StackProps props) {
        super(scope, id, props);

        vpc = Vpc.Builder.create(this, "AluraVpc")
                .maxAzs(1)  // Default is all AZs in region
                .natGateways(0)
                .build();
    }

    public Vpc getVpc() {
        return vpc;
    }
}
2 respostas

Trazendo mais informações do erro...

Esse é o meu AluraRdsStack Aqui está o AluraRdsStack

package com.myorg;

import software.amazon.awscdk.*;
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.ec2.InstanceType;
import software.amazon.awscdk.services.rds.*;
import software.constructs.Construct;

import java.util.Collections;

import static software.amazon.awscdk.services.ec2.Peer.anyIpv4;

public class AluraRdsStack extends Stack {
    public AluraRdsStack(final Construct scope, final String id, final Vpc vpc) {
        this(scope, id, null, vpc);
    }

    public AluraRdsStack(final Construct scope, final String id, final StackProps props, final Vpc vpc) {
        super(scope, id, props);

        var senha = CfnParameter.Builder.create(this, "senha")
                .type("String")
                .description("Senha do database pedidos-ms")
                .build();

        ISecurityGroup iSecurityGroup = SecurityGroup.fromSecurityGroupId(this, id, vpc.getVpcDefaultSecurityGroup());
        iSecurityGroup.addIngressRule(anyIpv4(),Port.tcp(3305));

        DatabaseInstance database = DatabaseInstance.Builder
                .create(this, "Rds-pedidos")
                .instanceIdentifier("alura-aws-pedido-db")
                .engine(DatabaseInstanceEngine.mysql(MySqlInstanceEngineProps.builder()
                        .version(MysqlEngineVersion.VER_8_0)
                        .build()))
                .vpc(vpc)
                .credentials(Credentials.fromUsername("admin",
                CredentialsFromUsernameOptions.builder()
                        .password(SecretValue.unsafePlainText(senha.getValueAsString()))
                        .build()))
                .instanceType(InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO))
                .multiAz(false)
                .allocatedStorage(10)
                .securityGroups(Collections.singletonList(iSecurityGroup))
                .vpcSubnets(SubnetSelection.builder()
                        .subnets(vpc.getPrivateSubnets())
                        .build())
                .build();

        CfnOutput.Builder.create(this, "pedidos-db-endpoint")
                .exportName("pedidos-db-endpoint")
                .value(database.getDbInstanceEndpointAddress())
                .build();

        CfnOutput.Builder.create(this, "pedidos-db-senha")
                .exportName("pedidos-db-senha")
                .value(senha.getValueAsString())
                .build();

    }
}

e aqui está o AluraAwsInfraApp

package com.myorg;

import software.amazon.awscdk.App;
import software.amazon.awscdk.Environment;
import software.amazon.awscdk.StackProps;

import java.util.Arrays;

public class AluraAwsInfraApp {
    public static void main(final String[] args) {
        App app = new App();

        AluraVpcStack vpcStack = new AluraVpcStack(app, "Vpc");
        AluraClusterStack clusterStack = new AluraClusterStack(app, "Cluster", vpcStack.getVpc());
        clusterStack.addDependency(vpcStack);

        AluraRdsStack rdsStack= new AluraRdsStack(app, "Rds", vpcStack.getVpc());
        rdsStack.addDependency(vpcStack);

        AluraServiceStack aluraServiceStack = new AluraServiceStack(app, "Service", clusterStack.getCluster());
        aluraServiceStack.addDependency(clusterStack);

        app.synth();
    }
}

As tentativas que fiz sempre deram o mesmo resultado e minhas pesquisas não foram muito eficientes a especifidade desse erro

Oii, Luiz! Tudo bem?

Está faltando a definição das IDs das sub-redes.

As IDs são necessárias para que o RDS possa ser criado corretamente. Você precisa especificar as IDs das sub-redes onde o RDS será implantado.

Para resolver esse problema, você precisa adicionar a definição delas no seu código. Você pode fazer isso usando o método .subnetIds() ao criar o recurso RDS. Por exemplo:

import software.amazon.awscdk.services.rds.SubnetSelection;

RdsInstance.Builder.create(this, "RdsInstance")
    .vpc(vpc)
    .subnetGroup(SubnetSelection.builder().subnetGroupName("meu--grupo-de-subredes").build())
    .build();

Lembrando que você precisa substituir o my-subnet-group pelo nome do grupo de sub-redes que você deseja usar para o RDS, ok?

Se a dúvida persistir, estamos aqui.

Abraços!

Caso este post tenha lhe ajudado, por favor, marcar como solucionado ✓.