使用无服务器框架时如何从AWS Lambda访问DynamoDB? [英] How to access DynamoDB from AWS Lambda when using the Serverless Framework?

查看:233
本文介绍了使用无服务器框架时如何从AWS Lambda访问DynamoDB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用无服务器框架来管理我的AWS Lambda部署。框架凭据可以访问DynamoDB资源,但是与框架一起部署的Lambda无法访问我的DynamoDB表。

I'm using the Serverless Framework to manage my AWS Lambda deploys. The framework credentials has access to DynamoDB resources, but my Lambda, deployed with the framework, can't access my DynamoDB tables.

如何为Lambda函数赋予适当的功能

How can I give my Lambda functions the proper access?

推荐答案

编辑:更新了Serverless Framework 1.x的答案。

EDIT: updated the answer for Serverless Framework 1.x.

解决方案是设置 iamRoleStatements 以允许Lambda访问DynamoDB资源。注意:无服务器框架使用的凭据必须具有相同DynamoDB资源的权限。

The solution is to set the iamRoleStatements to allow Lambda to access the DynamoDB resources. Note: the credentials used by the Serverless Framework must have permission to the same DynamoDB resources.


  1. 添加 iamRoleStatements 在您的 serverless.yml 中:

provider:
  name: aws
  runtime: nodejs4.3
  stage: dev
  region: us-east-1
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "dynamodb:*"
      Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/*"


  • 部署更改:

  • deploy the changes:

    > serverless deploy
    


  • 在功能级别授予权限(而不是允许所有功能访问DynamoDB),请在此处查看我的其他答案。

    To give permissions in a function level (instead of allowing all functions to access DynamoDB), see my other answer here.

    这篇关于使用无服务器框架时如何从AWS Lambda访问DynamoDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆