收到InvalidSignatureException错误,而我在机器上的时间正确

时间:2019-06-28 09:53:58

标签: amazon-web-services lambda terraform

terraform apply给我以下错误:

错误:创建Lambda函数时出错:InvalidSignatureException:签名已过期:20190628T091524Z现在早于20190628T092024Z(20190628T092524Z-5分钟)

许多建议在我运行terraform命令的本地计算机上确定时间,但这对我来说似乎不是问题。我的本地机器时间正确,那里没有问题。

这个没有解决我的问题:( Terraform apply failed due to mismatch time

1 个答案:

答案 0 :(得分:2)

我认为它的发生是由于互联网问题缓慢所致,因此,请按照以下步骤进行操作。

  • 即时安装NPM模块
  • 动态创建zip
  • 将zip压缩到s3
  • 然后从s3指定目标密钥,而不是从本地推送zip

这是工作代码。

 resource "null_resource" "npm" {
      provisioner "local-exec" {
        command = "cd ../lambda-functions/loadbalancer-to-es && npm install --prod=only && chmod -R 777 node_modules"
      }
    }

resource "aws_s3_bucket_object" "file_upload" {
  bucket = "${var.env_prefix_name}${var.s3_suffix}"
  key    = "lambda-functions/loadbalancer-to-es.zip"
  source = "${data.archive_file.source.output_path}"
  # etag   = "${filemd5("../lambda-functions/loadbalancer-to-es.zip")}"
}

# Zip the Lambda function on the fly
data "archive_file" "source" {
  type        = "zip"
  source_dir  = "../lambda-functions/loadbalancer-to-es"
  output_path = "../lambda-functions/loadbalancer-to-es.zip"
  depends_on  = ["null_resource.npm"]
}


# Created AWS Lamdba Function: Memory Size, NodeJS version, handler, endpoint, doctype and environment settings
resource "aws_lambda_function" "elb_logs_to_elasticsearch" {
  function_name = "${var.env_prefix_name}-alb-logs-to-elk-test"
  s3_bucket = "${var.env_prefix_name}${var.s3_suffix}"
  s3_key    = "${aws_s3_bucket_object.file_upload.key}"
  description   = "elb-logs-to-elasticsearch"
  memory_size   = 1024
  timeout       = 900
  runtime       = "nodejs8.10"
  role          = "${aws_iam_role.role.arn}"
  depends_on  = ["null_resource.npm" ]
  source_code_hash = "${base64sha256(data.archive_file.source.output_path)}"
  handler       = "index.handler"


  environment {
    variables = {
      ELK_DOCKTYPE = "some env"
    }
  }
}