2

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).

piisexactly3
  • 779
  • 7
  • 16

1 Answers1

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.

thomasmichaelwallace
  • 7,926
  • 1
  • 27
  • 33
  • I would imagine that the build-in lambda sdk will be updated sooner or later, so this will probably solve itself then even if I don't take any action. Thanks for your help – piisexactly3 May 14 '19 at 16:22
  • Once again the bearer of bad news, but the built-in aws-sdk only changes with each new runtime (as it is _potentially_ a breaking change for every deployed lambda), so I expect you won't get a higher version until the node 12 runtime is released. – thomasmichaelwallace May 14 '19 at 16:25
  • It might be bad news, but it still saves me a lot of hassle. Thanks again – piisexactly3 May 14 '19 at 17:21