我目前正在开发部署为 AWS Lambda 函数的 Node.JS 应用程序。当我尝试在本地访问路由时,它会以找不到页面进行响应。我列出了不同功能的不同配置文件。有些是公共路线,有些是受保护的路线。此问题仅发生在受保护的路由上。
我的配置文件: course.yml
handler: src/course/aicc/handler.do
events:
- http:
path: /aicc/{proxy+}
method: ANY
cors:
origin: '*'
headers:
- Accept
- Origin
- DNT
- User-Agent
- Referer
- X-experience-api-version
- x-amz-date
- x-requested-with
- X-Requested-With
- Content-Type # Part of the Default List
- X-Amz-Date # Part of the Default List
- Authorization # Part of the Default List
- X-Api-Key # Part of the Default List
- X-Amz-Security-Token # Part of the Default List
- X-Amz-User-Agent # Part of the Default List
allowCredentials: false
- http:
path: /aicc/
method: ANY
cors:
origin: '*'
headers:
- Accept
- Origin
- DNT
- User-Agent
- Referer
- X-experience-api-version
- x-amz-date
- x-requested-with
- X-Requested-With
- Content-Type # Part of the Default List
- X-Amz-Date # Part of the Default List
- Authorization # Part of the Default List
- X-Api-Key # Part of the Default List
- X-Amz-Security-Token # Part of the Default List
- X-Amz-User-Agent # Part of the Default List
allowCredentials: false
- schedule: rate(15 minutes) # here to avoid cold starts of the Lambda
从上面的配置文件中读取的 serverless.yml 文件:
- serverless-plugin-include-dependencies
- serverless-plugin-log-subscription
- serverless-offline
custom:
awsId: 8066631*****
logSubscription:
enabled: ${file(conf/vpc-${self:provider.stage}.js):es_lambda_enabled}
destinationArn: ${file(conf/vpc-${self:provider.stage}.js):es_lambda_function}
package:
excludeDevDependencies: true
exclude:
- conf/**
- lib/**
- spec/**
- .eslintrc.json
- .jsbeautifyrc
- package.json
- package-lock.json
- rebuildLocalModules.sh
- ToDoItems.md
include:
- ./project_modules/**
provider:
name: aws
runtime: nodejs10.x
memorySize: 128
timeout: 10
stage: ${opt:stage, 'dev'}
group: ${opt:group, 'course'}
region: us-east-2
logRetentionInDays: 3
deploymentBucket:
name: serverless-safetyserve-${self:provider.region}
environment:
STAGE: "${self:provider.stage}"
REGION: us-east-2
SSM_KEYS: "[\"/${self:provider.stage}/api\"]"
JWT_SECRET : ${ssm:/${self:provider.stage}/jwt/secret~true}
vpc:
securityGroupIds: ${file(conf/vpc-${self:provider.stage}.js):security}
subnetIds: ${file(conf/vpc-${self:provider.stage}.js):subnets}
iamRoleStatements:
- Effect: Allow
Action:
- lambda:InvokeFunction
Resource:
- "*"
- Effect: "Allow"
Action:
- "ssm:GetParameter"
- "ssm:GetParameters"
Resource:
- "arn:aws:ssm:${self:provider.region}:${self:custom.awsId}:parameter/${self:provider.stage}/*"
- Effect: "Allow"
Action:
- "ses:SendEmail"
- "ses:SendRawEmail"
Resource:
- "*"
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
- "s3:PutObjectAcl"
- "s3:DeleteObject"
Resource:
- "arn:aws:s3:::download.roadready.org/*"
- "arn:aws:s3:::safetyserve-cloudfront-logs/*"
- "arn:aws:s3:::static-sites-safetyserve/${self:provider.stage}/*"
- "arn:aws:s3:::${self:provider.stage}.roadready.org/*"
- "arn:aws:s3:::config-safetyserve/${self:provider.stage}/*"
- Effect: "Allow"
Action:
- "s3:GetObject"
- "s3:PutObject"
Resource:
- "arn:aws:s3:::reports-safetyserve/${self:provider.stage}/*"
- Effect: "Allow"
Action:
- "s3:ListBucket"
Resource:
- "arn:aws:s3:::static-sites-safetyserve"
- Effect: "Allow"
Action:
- "cloudfront:CreateInvalidation"
Resource:
- "*"
service: ${file(conf/sls-${self:provider.group}.yml):service}
functions: ${file(conf/sls-${self:provider.group}.yml):functions}
resources: ${file(conf/sls-${self:provider.group}.yml):resources}
虽然这不是受保护的路线,但我仍然面临这个问题。任何帮助将非常感激。