标签: serverless-framework

为什么我的无服务器Lambda无法访问S3存储桶和项目?

我确定我已经将我的Lambda设置为具有对私有桶的读/写访问权限; 更具体地说,我的lambda将执行s3.headObjects3.upload.为了让这个工作,我错过了什么?

我的Lambda的政策:

{
"Statement": [
    {
        "Resource": "arn:aws:logs:us-east-1:*:*",
        "Action": [
            "logs:CreateLogGroup",
            "logs:CreateLogStream",
            "logs:PutLogEvents"
        ],
        "Effect": "Allow"
    },
    {
        "Resource": "arn:aws:s3:::PRIVATE_BUCKET/folder_name/*",
        "Action": [
            "s3:GetObject",
            "s3:PutObject"
        ],
        "Effect": "Allow"
    }
],
"Version": "2012-10-17"
Run Code Online (Sandbox Code Playgroud)

}

我的S3存储策略:

 {
    "AWSTemplateFormatVersion" : "2010-09-09",
    "Description" : "Bucket that is read-accessible internally",
    "Parameters" : {
        "Environment" : {
            "Description" : "dev",
            "Type" : "String",
            "Default" : "dev",
            "AllowedValues" : [ "dev" ]
        }
    },
    "Resources" : {
        "PrivateBucket" : {
            "Type" : "AWS::S3::Bucket", …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 amazon-web-services aws-lambda serverless-framework

7
推荐指数
1
解决办法
4345
查看次数

API网关:无法启用CORS

我无法在 API 网关实例上启用 CORS,如下所示:

1、设置: 在此输入图像描述

2、结果: 在此输入图像描述

我已经尝试了很多事情,例如检查DEFAULT 4XXDEFAULT 5XX并按照某些帖子中的建议手动输入 Access-Control-Allow-Methods 。

如果我将鼠标悬停在错误上,我会得到:Invalid Response status code specified

我可以使用浏览器获取数据,但只能通过邮递员完成 POST 操作。我的 ReactJS 网站也不会发布,抛出:

Access to XMLHttpRequest at <ENDPOINT> from origin <S3-REACT-BUCKET> has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我读到我的 React 应用程序应该发送 CORS 标头(尚未实现),但我什至无法在 API 网关中启用 CORS!

cors aws-lambda aws-api-gateway serverless-framework serverless

7
推荐指数
1
解决办法
3303
查看次数

使用特定选项或环境变量在 AWS lambda 中启动 NodeJS 运行时

执行 AWS Lambda 时出现 NodeJS 弃用错误(使用节点 12.x):

[DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
Run Code Online (Sandbox Code Playgroud)

无法找到哪个模块/代码片段正在生成它。似乎没有任何内容引用_headers_headerNames

在 Node 中应该可以设置参数或环境变量,如此处解释--trace-deprecation和/或--trace-warnings和/或--throw-deprecation。在 lambda 的 AWS 控制台环境变量中设置一个或多个这些值时,不会显示任何额外信息。

AWS lambda 环境变量

为 AWS Lambda 设置此运行时参数的方法是什么?有没有办法捕获堆栈跟踪以了解不推荐使用的错误发生在哪里?

amazon-web-services node.js aws-lambda serverless-framework

7
推荐指数
1
解决办法
2452
查看次数

无服务器中的 Lambda 组是什么?

我正在研究serverless-plugin-split-stacks无服务器框架的插件,因为我已经达到了 200 个资源的 CloudFormation 限制。在其 Github 页面的“迁移策略”部分中,它说我有三个选择:

  • 佩尔拉姆达
  • 每种类型
  • 拉姆达集团

前两个,我有点明白他们的意思(但我不是百分百确定)。我的问题是关于最后一个选项。什么是 lambda 群?如何对 lambda 函数进行分组?是手动完成的还是自动分组的?

amazon-web-services serverless-framework split-stacks

7
推荐指数
1
解决办法
269
查看次数

如何使用 Serverless Framework 管理 Lambda 内 Aurora Serverless 数据 api 的 typeORM 连接

我在用着:

我正在连接到数据库,就像 github 中描述的那样,

const connection = await createConnection({
      type: 'aurora-data-api-pg',
      database: 'test-db',
      secretArn: 'arn:aws:secretsmanager:eu-west-1:537011205135:secret:xxxxxx/xxxxxx/xxxxxx',
      resourceArn: 'arn:aws:rds:eu-west-1:xxxxx:xxxxxx:xxxxxx',
      region: 'eu-west-1'
    })
Run Code Online (Sandbox Code Playgroud)

这就是我在 Lambda 函数中使用它的方式

export const testConfiguration: APIGatewayProxyHandler = async (event, _context) => {
  let response;
  try {
    const connectionOptions: ConnectionOptions = await getConnectionOptions();
    const connection = await createConnection({
      ...connectionOptions,
      entities,
    });
    const userRepository = connection.getRepository(User);
    const users = await userRepository.find();

    response = {
      statusCode: 200,
      body: JSON.stringify({ users }),
    }; …
Run Code Online (Sandbox Code Playgroud)

aws-lambda serverless-framework typeorm aws-aurora-serverless

7
推荐指数
1
解决办法
6394
查看次数

通过无服务器失败进行打字稿编译

我有一个基于 Typescript 的 Lambda 函数,可以正常编译,tsc但当我尝试通过无服务器部署时,Typescript 复杂性失败并出现以下错误:

Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Warning: "rootDir" from local tsconfig.json is overriden
Cannot locate handler - account. not found
 
  Error --------------------------------------------------
 
  Error: Typescript compilation failed. Please ensure handlers exists with ext .ts or .js
      at /Users/bob/Development/service-account/node_modules/serverless-plugin-typescript/src/typescript.ts:69:13
Run Code Online (Sandbox Code Playgroud)

相关的代码块account.ts是:

Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Warning: "rootDir" from local …
Run Code Online (Sandbox Code Playgroud)

typescript serverless-framework

7
推荐指数
1
解决办法
1万
查看次数

与 CloudFront 分配关联的 Lambda 函数无效或不具有所需的权限

因此,作为借口,我几乎不知道该怎么办。我研究了大约两个小时,通常我会继续下去,但我发现的信息都没有用。我怀疑这与 YAML (serverless.yml) 文件有关,但我不确定。我对该文件进行了多次更新,因此我将发布初始代码和当前代码,尽管没有任何区别。该代码在开发中完美运行,但在生产中会引发错误。您可以查看https://www.evote.space来复制此内容。

当前的

myNextApplication:
  service: myService
  component: "@sls-next/serverless-component@1.18.0"
  provider:
    name: aws
    runtime: nodejs12.x
    stage: dev
    profile: evote
    iam:
    role: rolenamegoesherebutnotonstackoverflow
  inputs:
    domain: "evote.space"
  functions:
    createuser:
      handler: data.createuser
    readTable:
      handler: data.readTable
  resources:
    Resources:
      usersTable:
        Type: AWS::DynamoDB::Table
        Properties:
          TableName: Users
          AttributeDefinitions:
          - AttributeName: userHash
            AttributeType: N
          KeySchema:
          - AttributeName: userHash
            KeyType: HASH
      votersTable:
        Type: AWS::DynamoDB::Table
        Properties:
          TableName: Voters
          AttributeDefinitions:
          - AttributeName: voterHash
            AttributeType: N
          KeySchema:
          - AttributeName: voterHash
            KeyType: HASH
      electionsTable:
        Type: AWS::DynamoDB::Table
        Properties:
          TableName: Elections
          AttributeDefinitions:
          - …
Run Code Online (Sandbox Code Playgroud)

amazon-cloudfront aws-lambda serverless-framework serverless

7
推荐指数
1
解决办法
1万
查看次数

使用无服务器框架将 Plotly/Dash 应用程序部署到 AWS

我正在尝试使用无服务器框架将 Plotly Dash 应用程序部署为 AWS Lambda。该应用程序在本地按预期运行,我可以使用serverless wsgi serve命令启动它。serverless deploy报告成功。然而,当调用时,lambda 失败并出现以下错误:

Traceback (most recent call last):
File "/var/task/wsgi_handler.py", line 44, in import_app
wsgi_module = importlib.import_module(wsgi_fqn_parts[-1])
File "/var/lang/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed …
Run Code Online (Sandbox Code Playgroud)

python amazon-web-services aws-lambda serverless-framework plotly-dash

7
推荐指数
1
解决办法
6702
查看次数

如何将 serverless.yml 文件拆分为多个文件?

我正在为我的 AWS 支持的应用程序使用无服务器框架。serverless.yml到目前为止,我一直在编写一个超长文件,其中包含我所有的 lambda 代码、资源、IAM 角色和状态机。我发现管理这个大文件非常困难。我该如何解决这个问题?有什么方法可以将我的serverless.yml文件分割成更小的、可管理的块吗?yml如果我能每人得到一份就太好了lambda。提前致谢

lambda yaml amazon-web-services serverless-framework serverless

7
推荐指数
1
解决办法
5653
查看次数

.env 文件上的无服务器弃用警告

我正在使用无服务器框架来部署 React Web 应用程序。我已经设置了用于部署的 CI/CD 管道。当执行无服务器模板时,我收到了几个弃用警告。

Serverless: Deprecation warning: Detected ".env" files. In the next major release variables from ".env" files will be automatically loaded into the serverless build process. Set "useDotenv: true" to adopt that behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#LOAD_VARIABLES_FROM_ENV_FILES
Serverless: Deprecation warning: Variables resolver reports following resolution errors:
              - Cannot resolve variable at "provider.profile": Value not found at "env" source
   From a next major this will be communicated with a thrown error.
            Set "variablesResolutionMode: 20210326" in your service …
Run Code Online (Sandbox Code Playgroud)

serverless-framework serverless aws-serverless

7
推荐指数
1
解决办法
1万
查看次数