小编mec*_*aph的帖子

将存储桶策略附加到无服务器生成的存储桶

我正在尝试使用无服务器创建一个 S3 存储桶,它可以工作,但是为了操作其中的文件,我需要一个存储桶策略。我很难理解在何处以及如何添加使用在第一次无服务器部署时创建的生成的 S3bucket 名称的策略

## serverless.yml##

service: vcc-nametags-api

# Use the serverless-webpack plugin to transpile ES6
plugins:
  - serverless-webpack
  - serverless-offline
  - serverless-ding

# serverless-webpack configuration
# Enable auto-packing of external modules
custom:
  # Our stage is based on what is passed in when running serverless
  # commands. Or fallsback to what we have set in the provider section.
  stage: ${opt:stage, self:provider.stage}
  # Set our DynamoDB throughput for prod and all other non-prod stages.
  # Load our webpack …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services serverless-framework

9
推荐指数
1
解决办法
6138
查看次数

无服务器 Lambda 和 API 网关的 CORS 问题

解决了

以下问题只是由我的 Lambda 中构造的响应对象的 body 属性引起的。我忘记对数据进行字符串化,body: data而不是返回body: JSON.stringify(data). 这个响应问题似乎触发了 API Gateway 的错误,导致请求失败并出现一些相当混乱的错误消息。

问题

我正在使用 React、Serverless 和 Stripe API 开发电子商务网站。我的前端 React 应用程序正在使用 Axios 向我的 Lambda 函数发出 GET 请求,该函数已通过 API 网关公开。Lambda 函数依次查询 Stripe API 并将 Stripe 响应数据返回给我的 React 应用程序。但是,当我的 React 应用程序尝试调用 Lambda 时,我遇到了 CORS 问题,它收到以下错误:

Failed to load: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 502.
Run Code Online (Sandbox Code Playgroud)

在 Insomnia 中查询 Lambda 终端节点会返回 502 响应 …

aws-lambda aws-api-gateway serverless-framework axios http-status-code-502

5
推荐指数
1
解决办法
6806
查看次数