Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 从Lambda读取AWS放大托管存储vault(私钥S3)对象_Amazon Web Services_Amazon S3_Aws Lambda_Amazon Iam_Aws Amplify - Fatal编程技术网

Amazon web services 从Lambda读取AWS放大托管存储vault(私钥S3)对象

Amazon web services 从Lambda读取AWS放大托管存储vault(私钥S3)对象,amazon-web-services,amazon-s3,aws-lambda,amazon-iam,aws-amplify,Amazon Web Services,Amazon S3,Aws Lambda,Amazon Iam,Aws Amplify,我有一个小的Angular应用程序,其中我将AWS Amplify与AWS Cognito用户池结合使用 管理和验证用户。我使用AWS Amplify存储API在S3中存储用户数据 我希望有一个Java AWS Lambda调用,它可以假定用户的身份并访问 存储在S3 bucket中的数据,就像用户在浏览器中登录的web应用程序一样。Lambda应该能够对来自经过身份验证的浏览器会话的传入AWS API网关请求进行身份验证,并将经过身份验证的用户身份和对象密钥映射到实际的S3位置,以便在将结果返

我有一个小的Angular应用程序,其中我将AWS Amplify与AWS Cognito用户池结合使用 管理和验证用户。我使用AWS Amplify存储API在S3中存储用户数据

我希望有一个Java AWS Lambda调用,它可以假定用户的身份并访问 存储在S3 bucket中的数据,就像用户在浏览器中登录的web应用程序一样。Lambda应该能够对来自经过身份验证的浏览器会话的传入AWS API网关请求进行身份验证,并将经过身份验证的用户身份和对象密钥映射到实际的S3位置,以便在将结果返回给客户端之前加载和处理该请求

在客户端,我只需使用
aws-amplify
中的
Auth
进行身份验证

import { Injectable } from '@angular/core';
import {Observable, throwError, from, BehaviorSubject} from 'rxjs';
import {Auth} from 'aws-amplify';

// ... lines omitted
import {CognitoUser} from 'amazon-cognito-identity-js';
// ... lines omitted

@Injectable({
  providedIn: 'root',
})
export class AccountService {

  // ... lines omitted
  authenticate(username: string, password: string): Observable<any> {
    return from(Auth.signIn(username, password));
  }
  // ... lines omitted
}
我想做的是:

  • 在Lambda中对传入的API网关请求进行身份验证,并在Lambda函数中假定与客户端浏览器会话具有相同的标识,以便我只能读取相同的数据集。(lambda调用只能为特定用户读取
    data.json
    :显然,每个用户都有自己的
    data.json
  • 查找经过身份验证的用户ID和指定密钥的放大vault存储路径,就像使用放大
    storage.vault.get(key)
    API调用一样。(lambda调用应该能够计算出该特定用户的
    data.json
    的实际S3位置)
  • // ... lines omitted
    import {BehaviorSubject, from, Observable, of, throwError} from 'rxjs';
    import {Storage} from 'aws-amplify';
    // ... lines omitted
    
    @Injectable({
      providedIn: 'root',
    })
    export class PreferencesService {
    
      // ... lines omitted
      private saveData(data: Data[]) {
        const dataAsJson: string = JSON.stringify(data);
        return from(Storage.vault.put('data.json', dataAsJson));
      }
    
      private getData(key: string) {
        return from(Storage.vault.get(key)).pipe(
          switchMap(dataUrl => {
            return this.http.get(dataUrl as string).pipe(
              map(it => {
                const data = it as Data[];
                return data;
              }),
              catchError(err => {
    
                if (err['status'] === 404) {
                  // HTTP 404 is translated to empty result
                  return of(null);
                } else {
                  return throwError(err);
                }
              }));
          }));