Amazon web services 使用AWS Lambda和API网关未知令牌的Terraform无服务器应用程序?

Amazon web services 使用AWS Lambda和API网关未知令牌的Terraform无服务器应用程序?,amazon-web-services,aws-lambda,terraform,aws-api-gateway,Amazon Web Services,Aws Lambda,Terraform,Aws Api Gateway,我正在学习地形,其中一口井在最后给了我一些问题 我有一个文件定义我的lambda,以及它与API网关的关系。到API网关的连接尚未测试,因为我似乎无法部署API网关 lambda.tf provider "aws" { region = "us-east-1" shared_credentials_file = "/home/camelType/.aws/credentials" profile = "

我正在学习地形,其中一口井在最后给了我一些问题

我有一个文件定义我的lambda,以及它与API网关的关系。到API网关的连接尚未测试,因为我似乎无法部署API网关

lambda.tf


provider "aws" {
    region = "us-east-1"
    shared_credentials_file = "/home/camelType/.aws/credentials"
    profile = "default" 
}


resource "aws_lambda_function" "example" {
    function_name = "ServerlessExample"

   # The bucket name as created earlier with "aws s3api create-bucket"
    s3_bucket = "camelType-serverless-example"
    s3_key    = "v1.0.0/example.zip"

   # "main" is the filename within the zip file (main.js) and "handler"
   # is the name of the property under which the handler function was
   # exported in that file.
    handler = "main.handler"
    runtime = "nodejs12.x"

    role = "${aws_iam_role.lambda_exec_role.arn}"
}



resource "aws_iam_role" "lambda_exec_role" {
    name = "lambda_exec_role"
    assume_role_policy = <<EOF
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": "sts:AssumeRole",
            "Principal": {
                "Service": "lambda.amazonaws.com"
            },
            "Effect": "Allow",
            "Sid": ""
        }
    ]
}
EOF
}

//Haven't tested below here

resource "aws_api_gateway_resource" "proxy" {
   rest_api_id = aws_api_gateway_rest_api.example.id
   parent_id   = aws_api_gateway_rest_api.example.root_resource_id
   path_part   = "{proxy+}"
}

resource "aws_api_gateway_method" "proxy" {
   rest_api_id   = aws_api_gateway_rest_api.example.id
   resource_id   = aws_api_gateway_resource.proxy.id
   http_method   = "ANY"
   authorization = "NONE"
}
resource "aws_api_gateway_rest_api" "example" {
    name        = "ServerlessExample"
    description = "Terraform Serverless Application Example"
}

resource "aws_api_gateway_integration" "lambda" {
    //issue here
    rest_api_id = aws_api_gateway_rest_api.example.id
    resource_id = aws_api_gateway_method.proxy.resource_id
    http_method = aws_api_gateway_method.proxy.http_method

    integration_http_method = "POST"
    type                    = "AWS_PROXY"
    uri                     = aws_lambda_function.example.invoke_arn
}

resource "aws_api_gateway_method" "proxy_root" {
    rest_api_id   = aws_api_gateway_rest_api.example.id
    resource_id   = aws_api_gateway_rest_api.example.root_resource_id
    http_method   = "ANY"
    authorization = "NONE"
}

resource "aws_api_gateway_integration" "lambda_root" {
    rest_api_id = aws_api_gateway_rest_api.example.id
    resource_id = aws_api_gateway_method.proxy_root.resource_id
    http_method = aws_api_gateway_method.proxy_root.http_method 

    integration_http_method = "POST"
    type                    = "AWS_PROXY"
    uri                     = aws_lambda_function.example.invoke_arn
}

resource "aws_api_gateway_deployment" "example" {
    depends_on = [
    aws_api_gateway_integration.lambda,
    aws_api_gateway_integration.lambda_root,
   ]

    rest_api_id = aws_api_gateway_rest_api.example.id
    stage_name  = "test"
}
我看过他们的一些教程,这是我第一次遇到问题。我肯定这是我的错误,但我已经检查过好几次了,似乎无法找出我做错了什么

根据注释,错误消息的复制粘贴为:error parsing/home/camelType/api_gateway.tf:At 7:18:Unknown token:7:18 IDENT aws_api_gateway_rest_api.example.id

该问题是由于使用terraform的旧版本(v0.11.11)而在配置文件中使用新版本的语法造成的

类似的问题也有报道:

解决方案是升级terraform。

根据评论

该问题是由于使用terraform的旧版本(v0.11.11)而在配置文件中使用新版本的语法造成的

类似的问题也有报道:


解决方案是升级terraform。

您能发布准确的错误消息吗?是的,错误消息发布在末尾。这里还有
Error:Error parsing/home/camelType/api_gateway.tf:At 7:18:Unknown token:7:18 IDENT aws_api_gateway_rest_api.example.id
您使用的是什么地形版本?有一些类似的问题表明您可能正在使用不支持新语法的旧版本?@Marcin就是这样。我还不习惯快照,它安装了v0.11.11。我以为我已经升级了,但它仍然在使用快照。多么可笑的错误啊。谢谢我现在在v0.13.0上,现在我在创建API Gateway:AccessDeniedException时遇到了一个更易于管理的
错误,这更容易排除故障。没问题。如果你不介意的话,我会提供一个包含更多信息的答案,以供将来参考:-)你能发布准确的错误消息吗?是的,错误消息发布在最后。这里还有
Error:Error parsing/home/camelType/api_gateway.tf:At 7:18:Unknown token:7:18 IDENT aws_api_gateway_rest_api.example.id
您使用的是什么地形版本?有一些类似的问题表明您可能正在使用不支持新语法的旧版本?@Marcin就是这样。我还不习惯快照,它安装了v0.11.11。我以为我已经升级了,但它仍然在使用快照。多么可笑的错误啊。谢谢我现在在v0.13.0上,现在我在创建API Gateway:AccessDeniedException时遇到了一个更易于管理的
错误,这更容易排除故障。没问题。如果你不介意的话,我会提供一个包含更多信息的答案,以供将来参考:-)再次感谢你的帮助!总有一天我会习惯快照……或者离开Ubuntu……我们拭目以待。再次感谢你的帮助!总有一天我会习惯快照……或者离开Ubuntu……我们拭目以待。