我正在使用AWS Code star并使用Express Web服务模板。代码明星创建Lambda并创建API网关API。该api的作品,它返回我想要的。我试图通过API网关启用CORS,AWS Code Star Express API启用CORS和集成响应
API网关 - > API - >资源 - >操作 - >启用CORS。
由于未为代理生成集成响应,因此无法在选项上设置CORS。这里是图像。
我想我必须通过YAML配置这个生成的选项合并响应和GET。
这里是我的YAML
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
- AWS::CodeStar
Parameters:
ProjectId:
Type: String
Description: AWS CodeStar projectID used to associate new resources to team members
Resources:
HelloWorld:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
Events:
GetEvent:
Type: Api
Properties:
Path:/
Method: get
GetById:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
Role:
Fn::ImportValue:
!Join ['-', [!Ref 'ProjectId', !Ref 'AWS::Region', 'LambdaTrustRole']]
Events:
GetEvent:
Type: Api
Properties:
Path: /api/getById
Method: get
这是我的LAMBDA处理程序。
'use strict';
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);
如果有人能帮助我如何调整CloudFormation模板,我将不胜感激。