0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

App RunnerからCognitoへ接続時にタイムアウトエラーが発生

Last updated at Posted at 2024-10-16

App RunnerからCognitoへ接続する際にタイムアウトが発生し少し時間がかかってしまったので整理

前提

つまずいたところ

App RunnerからCognitoのリクエストでタイムアウト

原因:ネットワーク

  • App Runnerはデフォルトではインターネット経由で外部にアクセス
  • ただし、VPC Connectorを利用すると、VPCネットワークに接続してプライベートにアクセスになる
  • CognitoはVPCの外にあるので、VPC Connecotr利用する場合App Runnerから接続できない状態になっていた。

対応:NatGatewayを設置

image.png

terraformで管理している場合は以下のようなリソースを追加すればOK

main.tf
/* ===================================
// NAT Gateway
// =================================== */

// public subnet
 resource "aws_subnet" "app_public_subnet1" {
   vpc_id            = aws_vpc.app_vpc.id
   cidr_block        = "172.16.10.0/24"
   availability_zone = "ap-northeast-1a"

     tags = {
     Name = "app_public_subnet1"
   }
 }

 resource "aws_internet_gateway" "app_igw" {
   vpc_id = aws_vpc.app_vpc.id
 }

// ルートテーブル for NAT Gateway
 resource "aws_route_table" "app_public_route_table" {
   vpc_id = aws_vpc.app_vpc.id
   route {
     cidr_block = "0.0.0.0/0"
     gateway_id = aws_internet_gateway.app_igw.id
   }
 }

// ルートテーブルに紐づくサブネット
 resource "aws_route_table_association" "public_route_table_association" {
   subnet_id      = aws_subnet.app_public_subnet1.id
   route_table_id = aws_route_table.app_public_route_table.id
 }

// EIP
 resource "aws_eip" "nat_eip" {
   domain = "vpc"
 }

 resource "aws_nat_gateway" "nat_gateway" {
   allocation_id = aws_eip.nat_eip.id
   subnet_id     = aws_subnet.app_public_subnet1.id
 }



 //ルートテーブルfor private subnet
 resource "aws_route_table" "app_private_route_table" {
  vpc_id = aws_vpc.app_vpc.id

  // すべての外部トラフィックをNAT Gatewayにルーティング
  route {
     cidr_block = "0.0.0.0/0"
     nat_gateway_id = aws_nat_gateway.nat_gateway.id
  }
}

これでネットワークの問題は解決するはずです!これで解決しない場合は、セキュリティグループなども確認してみると良いと思います。

関連

上記を解決したもののCognitoへの接続時に509エラーになったのでそれについては以下に書いています。
https://qiita.com/yukiyoshimura/items/0b6e31b117853049c228

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?