Amazon web services 从Lambda读取AWS放大托管存储vault(私钥S3)对象
我有一个小的Angular应用程序,其中我将AWS Amplify与AWS Cognito用户池结合使用 管理和验证用户。我使用AWS Amplify存储API在S3中存储用户数据 我希望有一个Java AWS Lambda调用,它可以假定用户的身份并访问 存储在S3 bucket中的数据,就像用户在浏览器中登录的web应用程序一样。Lambda应该能够对来自经过身份验证的浏览器会话的传入AWS API网关请求进行身份验证,并将经过身份验证的用户身份和对象密钥映射到实际的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位置,以便在将结果返
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
}
我想做的是:
data.json
:显然,每个用户都有自己的data.json
)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);
}
}));
}));