我正在尝试在Angular应用程序中使用AWS JS SDK。
考虑以下代码:
import * as AWS from 'aws-sdk';
import {Component, OnInit} from '@angular/core';
declare let AWSCognito: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
private _dynamodb;
constructor() {
AWS.config.region = 'eu-west-2'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'eu-west-2:xxyyzz'
});
this._dynamodb = new AWS.DynamoDB.DocumentClient();
}
ngOnInit() {
this._dynamodb.get({TableName: 'somename', Key: {projectId: 123321}}, (err, data) => {
})
}
}
执行上述代码时,出现以下错误:
ERROR TypeError: Cannot convert undefined or null to object
我看到是this._dynamodb.get
导致系统崩溃。
知道我在做什么错吗?
编辑:
完整堆栈跟踪:
ERROR TypeError: Cannot convert undefined or null to object
at hasOwnProperty (<anonymous>)
at isEndpointDiscoveryApplicable (discover_endpoint.js:279)
at Request.discoverEndpoint (discover_endpoint.js:322)
at Request.callListeners (sequential_executor.js:102)
at Request.emit (sequential_executor.js:78)
at Request.emit (request.js:683)
at Request.transition (request.js:22)
at AcceptorStateMachine.runTo (state_machine.js:14)
at state_machine.js:26
at Request.<anonymous> (request.js:38)