![](/img/trans.png)
[英]How to reference a zip file uploaded in an s3 bucket in your terraform lambda code?
[英]How to reference handler in Terraform for a Lambda on S3
我的 lambda 位於 S3 上的 zip 存檔中,並且我已在 AWS 上部署了 lambda 和 ZDB974ZA 網關。
這是我的項目根文件夾中的內容:
index.js
(入口點)package.json
README.md
node_modules
build.sh
(執行npm install
和zip -r project-folder.
) index.js
是入口點,在文件中,我使用https://github.com/spring-media/aws-lambda-router來處理路由:
exports.handler = router.handler({
proxyIntegration: {
routes: [
<routes_defined>
]
}
})
在下面的 terraform 基礎架構中(為簡單起見,編輯了許多資源參數),我正在使用模塊創建 lambda 資源,並將處理程序輸入為index.handler
並引用我的 S3 存儲桶。 所有其他資源都與 API 網關以及網關與 lambda 之間的權限相關:
module "module_name" {
handler = "index.handler"
s3_bucket = <references_s3_bucket>
}
resource "aws_api_gateway_rest_api" "api_gateway"
resource "aws_api_gateway_rest_api_policy" "api_gateway_policy"
resource "aws_api_gateway_resource" "proxy"
resource "aws_lambda_permission" "allow_api_gateway"
resource "aws_api_gateway_method" "proxy"
resource "aws_api_gateway_integration" "api_gateway_integration"
resource "aws_api_gateway_deployment" "api_gateway_deploy"
resource "aws_api_gateway_stage" "api_gateway_stage"
resource "aws_api_gateway_api_key" "api_gateway_key"
resource "aws_api_gateway_usage_plan" "api_gateway_usage_plan"
resource "aws_api_gateway_usage_plan_key" "api_gateway_usage_plan_key"
現在這在部署時並沒有顯示任何錯誤,直到我在我的 AWS 控制台上實際測試了 API 網關。 當我向 API 網關發出請求時,它響應錯誤index.js is undefined or not exported
exports 。 似乎是什么問題? 我已確保index.js
位於此問題中所述的根文件夾中: 索引處理程序未定義或未導出
哦,好吧,我認為index.handler
的設置是正確的,我只是錯過了我們設置別名的部分,並且我的正確版本沒有設置為活動。 一旦我將我的版本提升到活動版本,一切都會正常工作:D
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.