My lambda is in a zip archive on S3, and I have deployed both the lambda and an API Gateway on AWS.
Here's what I have in my project root folder:
index.js
(entrypoint)package.json
README.md
node_modules
build.sh
(a bash script that executesnpm install
andzip -r project-folder .
)
index.js
is the entry point, within the file, I'm using https://github.com/spring-media/aws-lambda-router to handle the routing:
exports.handler = router.handler({
proxyIntegration: {
routes: [
<routes_defined>
]
}
})
In my terraform infrastructure below (redacted many resources parameters for simplicity), I am creating a lambda resource using a module and feeding in the handler to be index.handler
and references my S3 bucket. All the other resources are related to the API gateway and permission between the gateway and the 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"
Now this doesn't show anything wrong upon deployment, until I actually test the API gateway on my AWS console. When I issue a request to the API gateway, it responds with an error of index.js is undefined or not exported
. What seems to be the issue? I've made sure that the index.js
is in the root folder as described in this issue: Index handler is undefined or not exported