标签: serverless

如何在我的 lambda 代码中使用 AWS 自定义授权程序中生成的权限?

我想生成一个自定义策略,该策略提供对 AWS 自定义授权方内的 DynamoDB 表的细粒度访问。这可能吗?

在无服务器中,我的配置如下所示:

functions:
  APIAuthorizer:
    handler: src/services/auth/handlers.apiAuthorizer
    cors: true
  GraphQLAPI:
    handler: src/services/graphql/handlers.apiHandler
    events:
      - http:
          path: "/api"
          method: post
          cors: true
          authorizer:
            name: APIAuthorizer
            type: request
            resultTtlInSeconds: 0
Run Code Online (Sandbox Code Playgroud)

我已验证我的自定义授权被调用,并生成各种权限(sts:AssumeRolelambda:InvokeFunctionexecute-api:Invoke,等)所需要的成功调用API处理器。所以我的自定义授权器正在工作,它提供的结果是必要的。

但是,当授权方包含 dynamodb 权限时,例如像 { Effect: "Allow", Action: "dynamodb: ", "Resource": " " }这样的语句

我的 API 处理程序(GraphQLAPI 函数)失败并显示如下消息

User: arn:aws:sts::<myaccountid>:assumed-role/<mydefaultrole>/myservice-mystage-GraphQLAPI is not authorized to perform: dynamodb:Query on resource: arn:aws:dynamodb:us-east-1:<myaccountId>:table/<mytable>/index/<someIndex> 
Run Code Online (Sandbox Code Playgroud)

(我注意到投诉是关于索引权限的,因此还尝试为该索引和/或所有索引添加特定权限,但这没有效果。)

经过多次不同尝试后的底线是,完全忽略了自定义授权方颁发的 dynamodb 权限。我的 lambda node.js 代码正在使用 AWS 节点 SDK,它应该从实例环境中获取权限。我认为这将包括自定义授权方生成的权限。

最后,我注意到有关如何加载凭据 …

amazon-dynamodb amazon-iam aws-lambda serverless lambda-authorizer

4
推荐指数
1
解决办法
679
查看次数

将 AWS::Route53::RecordSet DnsRecord 添加到无服务器 Cloudfront Distribution

我在如何将 route53 dns 记录与 serverless.yml 文件中的 S3 存储桶相关联上找到了这个

我已经尝试将其调整到部署 Cloudfront 分发版的情况

DnsRecord:
  Type: "AWS::Route53::RecordSet"
  Properties:
    AliasTarget:
      DNSName: <cloudfrontdistribution id>
      HostedZoneId: Z21DNDUVLTQW6Q
    HostedZoneName: ${self:custom.appFQDN}.
    Name:
      Ref: WebAppCloudFrontDistribution
    Type: 'CNAME'
Run Code Online (Sandbox Code Playgroud)

但我正在努力解决如何将分发 ID 作为参考而不是固定字符串获取。

我该怎么做?

aws-cloudformation amazon-route53 serverless aws-serverless

4
推荐指数
2
解决办法
2838
查看次数

AWS Lambda:在函数 A 后 10 分钟执行函数 B

我正在为时间敏感的应用程序开发无服务器后端。

是否可以在 Lambda 函数BXX 分钟后执行Lambda 函数A

我正在寻找一个干净的无服务器解决方案。使用setTimeout或类似的方法是一种无法接受的黑客行为。

示例:在执行 Lambda 函数 10 分钟后使用 SNS 发送通知。

amazon-web-services aws-lambda serverless

4
推荐指数
1
解决办法
2116
查看次数

参数中缺少必需的键“Bucket”

我正在尝试将一个简单的 lambda 函数部署到 aws,但我收到错误Missing required key 'Bucket' in params。我创建的用户拥有完整的 Lambda、S3、Cloudformation 和 Cloudwatch 访问权限。

JS

'使用严格';

module.exports.hello = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Go Serverless v1.0! Your function executed successfully!',
      input: event,
    }),
  };

  callback(null, response);

  // Use this code if you don't use the http event with the LAMBDA-PROXY integration
  // callback(null, { message: 'Go Serverless v1.0! Your function executed successfully!', event });
};
Run Code Online (Sandbox Code Playgroud)

YAML

service: lambda-demo

provider:
  name: …
Run Code Online (Sandbox Code Playgroud)

amazon-s3 aws-lambda serverless

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

部署到不同阶段时无服务器共享 API 网关错误

我正在使用无服务器版本 1.29.2

我创建了一个初始 cloudformation 脚本,该脚本创建了一个将由其他服务使用的 API GateWay REST API。所以这是负责它的 cloudformation 脚本。

{
   "AWSTemplateFormatVersion":"2010-09-09",
   "Description":"API",
   "Resources":{
      "APIGw":{
         "Type":"AWS::ApiGateway::RestApi",
         "Properties":{
            "Name":"API-GW"
         }
      }
   },
   "Outputs":{
      "ApiGwRestApiId":{
         "Value":{
            "Ref":"APIGw"
         },
         "Export":{
            "Name":"apigw-restApiId"
         }
      },
      "eyesApiGwRestApiRootResourceId":{
         "Value":{
            "Fn::GetAtt":[
               "APIGw",
               "RootResourceId"
            ]
         },
         "Export":{
            "Name":"apigw-rootResourceId"
         }
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试部署的应用程序的 serverless.yml。

service: template-test-service

provider:
  name: aws
  runtime: python3.6
  region: eu-central-1
  stage: ${self:custom.environment.stage}
  environment:
    stage: ${self:custom.environment.stage}
  apiGateway:
    restApiId:
      'Fn::ImportValue': apigw-restApiId
    restApiRootResourceId:
      'Fn::ImportValue': apigw-rootResourceId
Run Code Online (Sandbox Code Playgroud)

当我执行一个sls deploy --stage dev一切正常时,但是当我执行另一个部署到sls deploy --stage prod

出现此错误。

Another resource …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services api-gateway serverless

4
推荐指数
2
解决办法
3159
查看次数

Apollo 服务器 + Lambda + 订阅

是否可以通过订阅运行 Apollo GraphQL Lambda 后端?据我了解,GraphQL 订阅使用 websockets,所以我想除非你使用 Redis 作为消息代理,否则这是不可能的,但我想验证它,因为它没有在 Apollo Docs 的任何部分中说明。

lambda apollo graphql apollo-server serverless

4
推荐指数
2
解决办法
2685
查看次数

无服务器 502 错误网关

我可以按照文档创建一个简单的无服务器函数,但是当我添加http侦听器时,我502 Bad Gateway在尝试访问我的端点时不断收到一个。

我该如何调试?

'use strict';

module.exports.hello = async (event, context) => {
  return {
    statusCode: 200,
    body: {
      message: 'Go Serverless v1.0! Your function executed successfully!',
      input: event,
    },
  };
};
Run Code Online (Sandbox Code Playgroud)

无服务器.yaml

service: playing-with-serverless # NOTE: update this with your service name

provider:
  name: aws
  runtime: nodejs8.10

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: hello
          method: get
Run Code Online (Sandbox Code Playgroud)

我已经部署了我的功能

service: playing-with-serverless # NOTE: update this with your service name

provider:
  name: aws
  runtime: nodejs8.10

functions: …
Run Code Online (Sandbox Code Playgroud)

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

4
推荐指数
1
解决办法
4730
查看次数

使用 Python 上传 Azure Cloud Functions HTTP 文件

我在 Azure 上创建了一个带有 HTTP 触发器的云函数,我希望能够使用表单处理文件上传。
我的入口点是这样的:

def main(req: func.HttpRequest) -> func.HttpResponse:
    body = req.get_body()
    headers=req.headers
    ...
Run Code Online (Sandbox Code Playgroud)

问题是我得到的body是原始二进制文件,我不知道如何解码它并获取上传的文件。

有谁知道实现这一目标的好方法?

azure python-3.x azure-functions serverless

4
推荐指数
1
解决办法
1414
查看次数

CosmosDB 更改提要、租用和 azure 函数

我最近开始使用 Azure CosmosDB 和函数。在阅读文档https://docs.microsoft.com/pl-pl/azure/cosmos-db/change-feed-processor 时,我发现了一些对我来说很难理解的东西。实际上是否可以在许多功能之间共享更改提要,以便它们由同一个数据库操作触发?什么是租赁集合,它解决了什么问题。租赁的目的是什么?我想对这些术语有一个基本的解释。在我提供的链接中,据说可以在两个功能之间共享租约,但据说租用对象具有所有者财产。

azure azure-functions azure-cosmosdb serverless

4
推荐指数
1
解决办法
3185
查看次数

如何在 Google Cloud 中运行无服务器批处理作业

我有一个需要几个小时才能运行的批处理作业。如何在 Google Cloud 上以无服务器方式运行它?

AppEngine、Cloud Functions 和 Cloud Run 的时间限制为 10-15 分钟。我不想在 Apache Beam 中重写我的代码。

是否有等效于 Google Cloud 上的 AWS Batch?

batch-processing google-cloud-platform google-cloud-functions serverless google-cloud-run

4
推荐指数
2
解决办法
1963
查看次数