You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform部署LocalStack时API Gateway未部署且无报错问题排查

Terraform部署LocalStack时S3正常但API Gateway无部署无报错

问题详情

  • 运行环境:WSL(Linux),通过Terraform将配置部署到LocalStack Pro
  • 核心现象:配置中的S3 Bucket资源能正常部署,但aws_api_gateway_rest_api资源完全未部署;Terraform执行全程无任何报错提示
  • 已尝试的排查操作:重置LocalStack容器、删除Terraform缓存文件(.terraform目录、terraform.tfstate等),问题依旧;查看LocalStack日志,未发现与API Gateway部署相关的错误
  • 验证:使用AWS CLI命令aws apigateway create-rest-api --name "test-api-cli" --endpoint-url http://localhost:4566可成功手动创建API网关,说明LocalStack的API Gateway服务本身功能正常

相关配置文件

main.tf

provider "aws" {
  region     = "eu-west-1"
  access_key = "test"
  secret_key = "test"

  endpoints {
    apigateway     = "http://localhost:4566"
    cloudwatch     = "http://localhost:4566"
    dynamodb       = "http://localhost:4566"
    ec2            = "http://localhost:4566"
    events         = "http://localhost:4566"
    iam            = "http://localhost:4566"
    kms            = "http://localhost:4566"
    lambda         = "http://localhost:4566"
    logs           = "http://localhost:4566"
    s3             = "http://localhost:4566"
    sns            = "http://localhost:4566"
    sts            = "http://localhost:4566"
  }

  skip_credentials_validation     = true
  skip_metadata_api_check         = true
  skip_requesting_account_id      = true
  s3_use_path_style               = true
}


terraform {
    required_providers {
      aws = {
        source  = "hashicorp/aws"
        version = "~> 4"
      }
    }
    required_version = ">= 1.1"
 }


resource "aws_s3_bucket" "test" {
  bucket = "my-test-bucket"
}

resource "aws_api_gateway_rest_api" "test_api" {
  name = "test-api-only"
}

LocalStack Docker Compose配置

version: "3.8"
services:
  localstack:
    image: localstack/localstack-pro
    container_name: localstack-pro
    ports:
      - "4566:4566"
      - "4571:4571"
    environment:
      - LOCALSTACK_AUTH_TOKEN=[有效Pro令牌]
      - LOCALSTACK_EDITION=pro
      - LOCALSTACK_SERVICES=apigateway,cloudwatch,logs,iam,kms,sts,lambda,s3,dynamodb,events,sns
      - LOCALSTACK_DEBUG=1
    volumes:
      - ./localstack-data:/var/lib/localstack
      - /var/run/docker.sock:/var/run/docker.sock

补充信息

Terraform部署计划结果显示仅S3 Bucket被标记为已部署,API Gateway资源未出现在部署计划中(附截图)

内容的提问来源于stack exchange,提问作者HashtagForgotName

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 17:28:21