我正在使用无服务器创建一个web应用程序,该应用程序从S3桶中为其静态内容(例如web字体)提供服务。S3桶被配置为serverless.yml文件中的一个资源。其CORS配置将AllowOrigin设置为通配符。
我希望将其更改为具有由Serverless创建的服务的http端点的AllowOrigin,例如31alib51b6.execute-api.eu-west-1.amazonaws.com。
我想知道是否可以在serverless.yml文件本身中配置它。
我的示例serverless.yml文件:
service: example-service
provider:
name: aws
runtime: nodejs4.3
region: eu-west-1
functions:
web:
handler: handler.handler
name: ${self:service}-${self:provider.stage}
description: ${self:service} web application - ${self:provider.stage}
events:
- http:
path: web
method: get
- http:
path: web/{proxy+}
method: get
resources:
Resources:
S3Assets:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-${self:provider.stage}-assets
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
- HEAD
AllowedOrigins:
- "*"发布于 2017-01-25 22:48:37
可以使用以下语句定义AllowedOrigin:
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
- HEAD
AllowedOrigins:
- Fn::Join:
- ""
- - "https://"
- Ref: ApiGatewayRestApi
- ".execute-api.eu-west-1.amazonaws.com""Ref: ApiGatewayRestApi“引用生成的API的内部名称。
https://stackoverflow.com/questions/41860539
复制相似问题