简体   繁体   English

在其他AWS账户中查询Dynamodb-无服务器框架

[英]Querying Dynamodb in a different AWS account - Serverless Framework

I need to connect to the dynamoDB table in one AWS account from lambda of a different AWS account. 我需要从另一个AWS账户的lambda连接到一个AWS账户中的dynamoDB表。 Currently, I'm trying to connect to dynamodb through Serverless Offline. 当前,我正在尝试通过无服务器脱机连接到dynamodb。 I'm able to connect to a table in my AWS account but get an error when trying to connect to dynamoDB table in another account. 我可以连接到我的AWS账户中的表,但是尝试连接到另一个账户中的dynamoDB表时出现错误。

Error: Request Not Found. 错误:找不到请求。 (I have checked twice. The table does exist.) (我检查了两次。该表确实存在。)

The role I'm using in the serverlesss.yml has full admin privileges(including DynamoDB) 我在serverlesss.yml中使用的角色具有完整的管理员特权(包括DynamoDB)

serverless.yml

provider:
  name: aws
  runtime: nodejs6.10
  role: "arn:aws:iam::******:role/abcRole"
  iamRoleStatements:
    - Effect: Allow
      Action: ["dynamodb:*"]
      Resource: "arn:aws:dynamodb:us-east-1:*:*"



db.js

let dynamodbOnlineOptions = {
    region: 'us-east-1'
};

let client = new AWS.DynamoDB.DocumentClient(dynamodbOnlineOptions);

I think I'm making some mistake with permissions, but I'm able to identify the problem. 我认为我在权限上犯了一些错误,但是我能够找出问题所在。 Please help. 请帮忙。

The way forward I think is to create a cross account role that has access to that table, then have your lambda function assume that role. 我认为前进的方法是创建一个可以访问该表的交叉帐户角色,然后让您的lambda函数承担该角色。

Create the cross account role in the account that has the Dynamodb table and give it access to that. 在具有Dynamodb表的帐户中创建交叉帐户角色,并对其进行访问。

http://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html http://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html

Inside your lambda function have it assume that role and get temporary credentials to access that table. 在您的lambda函数内部,它承担了该角色并获得临时凭据以访问该表。

http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM