How to get past errors using putParameter with aws-sdk for nodejs in Lambda?

48
May 15, 2019, at 9:20 PM

I'm trying to set a parameter using putParameter in the AWS SDK for JavaScript in Node.js. In particular, I'd like to take advantage of the "Advanced" Tier, with an Expiration policy and Tags if possible. When I execute my code, I keep getting errors like:

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

I suspected the issue was around the aws-sdk version I was using, so I've tried running the code locally using SAM local, and from Lambda functions using the nodejs8.10 and nodejs10.x environments. The errors do not go away.

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();
};

I would expect this code to work and set a parameter with the expiration. However, it appears that the sdk doesn't recognize the "Policies" and "Tier" parameters, which are available according to the documentation. I don't know if it's an issue of waiting for the newest AWS SDK for JavaScript, but the runtimes page suggest that nodejs10.x is running AWS SDK for JavaScript 2.437.0.

It might be helpful to know that I can get the code running correctly without the parameters in question (ie, just the "Name", "Type", and "Value" parameters).

Answer 1

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.

READ ALSO
Pass type to function or create type from object

Pass type to function or create type from object

I have function, in which I need to use type, passed like one of function parameters:

28
NodeJS plans to support import/export es6 (es2015) modules

NodeJS plans to support import/export es6 (es2015) modules

I've been looking all over the internet without a clear answer for this

18
Sequelize ordering with nested associations

Sequelize ordering with nested associations

I have an included model where I need to sort by the same property but with two conditionals

43
Node app segfault on Heroku: std::bad_alloc and exit code 134

Node app segfault on Heroku: std::bad_alloc and exit code 134

I am having difficulty understanding this heroku stack traceMy app has been running very well both locally and in Heroku for a few years now

23