Aws-sdk-js: sns.subscribe does not allow parameters defined in the API documentation

Created on 20 Jun 2018  路  4Comments  路  Source: aws/aws-sdk-js

I've taken the example code from the API documentation (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#subscribe-property) and am unable to use the optional parameters for sns.subscribe.

Example from the docs:

var params = {
  Protocol: 'STRING_VALUE', /* required */
  TopicArn: 'STRING_VALUE', /* required */
  Attributes: {
    '<attributeName>': 'STRING_VALUE',
    /* '<attributeName>': ... */
  },
  Endpoint: 'STRING_VALUE',
  ReturnSubscriptionArn: true || false
};
sns.subscribe(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

My code (in a Lambda function):

    const AWS = require("aws-sdk");

    var filterPolicy = {
        "type": [ "type1" ],
        "id": [ "1", "2" ]
    };

    var params = {
        Protocol: 'https', 
        TopicArn: MY_ARN,
        Attributes: {
            'FilterPolicy': JSON.stringify(filterPolicy),
        },
        Endpoint: webhookUrl,
        // ReturnSubscriptionArn: true
    };
    sns.subscribe(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else     console.log(data);           // successful response
    });

Including ReturnSubscriptionArn or Attributes causes the following error in the Lambda console:

UnexpectedParameter: Unexpected key 'Attributes' found in params
    at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:77:14)
    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
    at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)
    at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:125:42)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at callNextListener (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at /var/runtime/node_modules/aws-sdk/lib/event_listeners.js:85:9
    at finish (/var/runtime/node_modules/aws-sdk/lib/config.js:320:7)
    at /var/runtime/node_modules/aws-sdk/lib/config.js:338:9
  message: 'Unexpected key \'Attributes\' found in params',
  code: 'UnexpectedParameter',
  time: 2018-06-19T20:46:47.160Z } 'UnexpectedParameter: Unexpected key \'Attributes\' found in params
    at ParamValidator.fail (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:50:37)
    at ParamValidator.validateStructure (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:77:14)
    at ParamValidator.validateMember (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:88:21)
    at ParamValidator.validate (/var/runtime/node_modules/aws-sdk/lib/param_validator.js:34:10)
    at Request.VALIDATE_PARAMETERS (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:125:42)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at callNextListener (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
    at /var/runtime/node_modules/aws-sdk/lib/event_listeners.js:85:9
    at finish (/var/runtime/node_modules/aws-sdk/lib/config.js:320:7)
    at /var/runtime/node_modules/aws-sdk/lib/config.js:338:9'

Commenting them out allows the code to run without error.

service-api

Most helpful comment

@Blackbaud-ChristiSchneider
The Attributes and ReturnSubscriptionArn properties were added to sns.subscribe in version 2.250.1 of the SDK.

The version of the SDK in Lambda is not updated as frequently as SDKs are released. It looks like as of right now, version 2.249.1 of the SDK is what's included in Lambda:
https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

If you want to use a newer version of the SDK, you can upload a project to Lambda that includes a copy of the aws-sdk in it.

All 4 comments

which version of SDK are you using? Does this exist on the newest version?

@Blackbaud-ChristiSchneider
The Attributes and ReturnSubscriptionArn properties were added to sns.subscribe in version 2.250.1 of the SDK.

The version of the SDK in Lambda is not updated as frequently as SDKs are released. It looks like as of right now, version 2.249.1 of the SDK is what's included in Lambda:
https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html

If you want to use a newer version of the SDK, you can upload a project to Lambda that includes a copy of the aws-sdk in it.

Oh My God!!! I thought I was going crazy...

How... why?.... I lost 3 hours on this.

thanks @chrisradek for this information

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings