0

我目前正在开发一个在 AWS 基础设施上运行的节点应用程序,它可以访问 DynamoDB 和 SSM。

我对 Node 的熟练程度不足以创建 MVCE,但这些都是与我相关的部分:

const AWS = require('aws-sdk')
AWS.config.update({ region: 'eu-west-1' })
const ddb = new AWS.DynamoDB.DocumentClient()
const ssm = new AWS.SSM()

const ssmQueryParams = {
  Name: '/foo/bar/tablename',
  WithDecryption: true
}

let ssmQueryResult
ssmQueryResult = (await ssm.getParameter(ssmQueryParams).promise())

const tableName = ssmQueryResult.Parameter.Value

const ddbParams = {
  TableName: tableName,
  Key: {
    'foo_id': fooId
  }
}
const ddbQueryResult = (await ddb.get(ddbParams).promise())

所以我想从 SSM 获取 DynamoDB 表名。如果我删除 SSM 部分,则代码有效。但有了它,我得到

{ Error: connect EHOSTUNREACH 169.123.123.123:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
  message: 'Missing credentials in config',
  errno: 'EHOSTUNREACH',
  code: 'CredentialsError',
  syscall: 'connect',
  address: '169.123.123.123',
  port: 80,
  time: 2019-06-25T12:34:02.909Z,
  originalError:
   { message: 'Could not load credentials from any providers',
     errno: 'EHOSTUNREACH',
     code: 'CredentialsError',
     syscall: 'connect',
     address: '169.123.123.123',
     port: 80,
     time: 2019-06-25T12:34:02.909Z,
     originalError:
      { errno: 'EHOSTUNREACH',
        code: 'EHOSTUNREACH',
        syscall: 'connect',
        address: '169.123.123.123',
        port: 80,
        message: 'connect EHOSTUNREACH 169.123.123.123:80' } } }

那么,为什么我可以访问 DynamoDB 上的数据,但是当我想从 SSM 读取数据时,却出现凭据错误?

编辑:添加accessKeyIdsecretAccessKeyAWS.config.update不是一种选择。

4

1 回答 1

0

我忘记提供 ARN

arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess

当我给

arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess
于 2019-06-25T14:46:10.367 回答