2

我正在尝试在AWS SDK for JavaScript in Node.js中使用 putParameter 设置参数。特别是,我想利用“高级”层,如果可能的话,带有过期策略和标签。当我执行我的代码时,我不断收到如下错误:

There were 2 validation errors:
* UnexpectedParameter: Unexpected key 'Policies' found in params
* UnexpectedParameter: Unexpected key 'Tier' found in params

我怀疑问题出在我使用的 aws-sdk 版本上,所以我尝试使用SAM local在本地运行代码,并使用 nodejs8.10 和 nodejs10.x 环境从 Lambda 函数运行代码。错误不会消失。

const AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
const ssm = new AWS.SSM({apiVersion: '2014-11-06'});

exports.lambdaHandler = async () => {

    const tokenExpiration = new Date();
    tokenExpiration.setSeconds(tokenExpiration.getSeconds() + 60);

    await ssm.putParameter({
        Name: 'SECRET_TOKEN',
        Type: 'SecureString',
        Value: '12345',
        Policies: JSON.stringify([
            {
               "Type":"Expiration",
               "Version":"1.0",
               "Attributes":{
                  "Timestamp": tokenExpiration.toISOString()
               }
            }
        ]),
        Overwrite: true,
        Tier: 'Advanced'
    }).promise();
};

我希望这段代码能够工作并设置一个过期参数。但是,SDK 似乎无法识别文档中提供的“策略”和“层”参数。我不知道这是否是等待最新的 AWS SDK for JavaScript 的问题,但运行时页面表明 nodejs10.x 正在运行 AWS SDK for JavaScript 2.437.0。

知道我可以在没有相关参数(即,只有“名称”、“类型”和“值”参数)的情况下正确运行代码可能会有所帮助。

4

1 回答 1

2

Unfortunately both Tier and Policies weren't added until v2.442.0 (see diff)

This means that to use these features you'll have to deploy with the version of the aws-sdk you're developing against.

It should be noted that either developing/testing against the built-in version, or deploying with the aws-sdk you do use, is often cited as good practice. If you're deploying your version you can use explicit client imports (e.g. const SSM = require('aws-sdk/clients/ssm') to keep the deployment size down. This is even more effective if you develop against the preview AWS-SDK Version 3.

于 2019-05-14T16:10:12.773 回答