AWS |使用DynamoDB会导致“错误TypeError:无法将未定义或null转换为对象”

时间:2018-11-10 15:03:21

标签: typescript amazon-web-services amazon-dynamodb

我正在尝试在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)

0 个答案:

没有答案