質問失礼します。
未経験ですが転職を目指してプログラムを勉強しております。
現在 AWSでインフラを構築し、サービスディスカバリを使用してフロントエンドアプリからバックエンドアプリの別コンテナにリクエストを送りたいのですが、名前解決に失敗してしまいます。
js
POST http://sd_api.myapp:3000/api/users net::ERR_NAME_NOT_RESOLVED
同vpc内にあるec2から以下のコマンドで確認すると名前解決はできていそうでした。
$ dig +short sd_api.myapp 10.0.0.1 10.0.0.2
awsはterraformで構築しており以下のようになっております。
js
//サービスディスカバリ resource "aws_service_discovery_private_dns_namespace" "myapp" { name = "myapp" vpc = aws_vpc.vpc.id } resource "aws_service_discovery_service" "sd_api" { name = "sd_api" dns_config { namespace_id = aws_service_discovery_private_dns_namespace.myapp.id dns_records { ttl = 10 type = "A" } routing_policy = "MULTIVALUE" } health_check_custom_config { failure_threshold = 1 } } //apiコンテナ定義 resource "aws_ecs_service" "api_container" { name = "api_container" cluster = aws_ecs_cluster.cluster.arn task_definition = aws_ecs_task_definition.api_container.arn desired_count = 1 launch_type = "FARGATE" platform_version = "1.4.0" network_configuration { assign_public_ip = false security_groups = [ module.api_sg.security_group_id ] subnets = [ aws_subnet.private-1a.id, aws_subnet.private-1c.id ] } service_registries { registry_arn = aws_service_discovery_service.sd_api.arn } } //フロントコンテナ定義 resource "aws_ecs_service" "front_container" { name = "front_container" cluster = aws_ecs_cluster.cluster.arn task_definition = aws_ecs_task_definition.front_container.arn desired_count = 1 launch_type = "FARGATE" platform_version = "1.4.0" health_check_grace_period_seconds = 60 network_configuration { assign_public_ip = false security_groups = [ module.front_sg.security_group_id, ] subnets = [ aws_subnet.private-1a.id, aws_subnet.private-1c.id ] } load_balancer { target_group_arn = aws_lb_target_group.front_container.arn container_name = "front_container" container_port = 8080 } }
terraformの設定で間違っている箇所があるのでしょうか?
フロントエンドアプリは、どこで動いているのでしょうか?
フロントエンドアプリが動いている PC 等からバックエンドアプリにアクセスは可能ですか?
フロントエンドアプリも別のfargateコンテナで動いています!
フロントエンドのコンテナ定義追記しました!
ec2からバックエンドアプリにリクエストを送れるかということですか?
ecsをprivateサブネットに入れていることや、リクエストの方法↓が間違っているのでしょうか。。。
POST http://sd_api.myapp:3000/api/users
みなさんコメント有難うございました。
まだ回答がついていません
会員登録して回答してみよう