简体   繁体   English

如何以访客用户身份访问AWS DynamoDB?

[英]How can I access an AWS DynamoDB as a guest user?

I am using aws-amplify and aws-sdk in Angular JS/Typescript. 我在Angular JS / Typescript中使用aws-amplify和aws-sdk。 I can successfully access my AWS DynamoDB as an authenticated user. 我可以通过身份验证的用户成功访问我的AWS DynamoDB。

I am also trying to add guest user access for a certain table in Dynamo, but I am struggling to understand how I would get a reference to the DynamoDB without any credentials. 我还试图为Dynamo中的某个表添加访客用户访问权限,但是我在努力了解如何在没有任何凭据的情况下获得对DynamoDB的引用。

My code looks like this at the moment 我的代码目前看起来像这样

   getDocumentClient() {
    return Auth.currentCredentials()
     .then(credentials => new AWS.DynamoDB.DocumentClient({ credentials: credentials }))
     .catch(err => logger.debug('error getting document client', err));

How would I do something similar to get access to the DynamoDB as an unauthenticated guest user? 我将如何做类似的事情来以未经身份验证的来宾用户身份访问DynamoDB?

Cheers 干杯

Lee 背风处

Try makeUnauthenticatedRequest . 尝试makeUnauthenticatedRequest

Here's an example with S3 - I've shown this because I know you can make requests to S3 from the AWS SDK as an unauthenticated user. 这是S3的一个示例-之所以展示了这一点,是因为我知道您可以以未经身份验证的用户身份从AWS开发工具包向S3发出请求。 I'm assuming that this will also work for DynamoDB but have not tested it. 我假设这也适用于DynamoDB,但尚未对其进行测试。

var s3 = new AWS.S3();

var params = {
    Bucket: 'mybucket'
};

s3.makeUnauthenticatedRequest('listObjects', params, callback);

The more strategic approach would be Amazon Cognito Identity Pools which support unauthenticated/guest identities. 更具战略意义的方法是支持未经身份验证/来宾身份的Amazon Cognito身份池。 Cognito vends an identity and AWS credentials, and you can configure an IAM role allowing DynamoDB read access for unauthenticated identity types. Cognito出售身份和AWS凭证,您可以配置IAM角色,以允许DynamoDB对未经身份验证的身份类型进行读取访问。

I think you can refer to what is mentioned in the blog post below. 我认为您可以参考以下博客文章中提到的内容。

https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for-dynamodb/ https://aws.amazon.com/blogs/compute/using-amazon-api-gateway-as-a-proxy-for-dynamodb/

The basic idea is to use API Gateway as a proxy for DynamoDB API. 基本思想是使用API​​网关作为DynamoDB API的代理。 Permission to access DynamoDB is granted to API Gateway via execution role, and API Gateway is configured to open to public. 通过执行角色将访问DynamoDB的权限授予API网关,并且将API Gateway配置为向公众开放。 In doing so, the flow will be as follows: 这样做的流程如下:

Web Browser <----- HTTPS -----> API Gateway <----- AWS Service Proxy integration -----> DynamoDB

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

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