14

I'm trying to get the ssm parameter inside my nodejs project, is IAM credentials I and wrote a test in my elastic beanstalk instance and works. The problem is inside the project. Any ideas why?

// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');

AWS.config.update({region: 'us-east-1'});

var ssm = new AWS.SSM();

var options = {
  Name: '/test/test', /* required */
  WithDecryption: false
};
var parameterPromise =  ssm.getParameter(options).promise();

parameterPromise.then(function(data, err) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

Otavio Carvalho
  • 271
  • 1
  • 3
  • 10
  • what's the output of the above sample code? – EddieDean Oct 30 '19 at 22:33
  • In the /home of instance return the correct parameter value, inside of nodejs project the promise is never resolved or rejected – Otavio Carvalho Oct 30 '19 at 23:13
  • Can you elaborate what you mean by inside of the nodejs project? Does the CLI succeed but your node code fails? Are you providing sufficient credentials for your application? Can you share the IAM role/policy you are using for the application? – Simon Oct 30 '19 at 23:17
  • Yes the CLI works fine, node is a web application with nestjs. – Otavio Carvalho Oct 31 '19 at 00:15
  • Are you sure you're in the right region for SSM? Does Elastic Beanstalk have a role with a policy that gives it permission to read from SSM? – Simon Oct 31 '19 at 00:33
  • yep, the region is correct, the policy is correct too, because the CLI works.. – Otavio Carvalho Oct 31 '19 at 01:38

1 Answers1

11

I discovered, the same of this https://github.com/localstack/localstack/issues/1107

need to pass the region in the SSM constructor

var ssm = new AWS.SSM({region: 'us-east-1'});

seems to be a bug

tks

Otavio Carvalho
  • 271
  • 1
  • 3
  • 10
  • It's not a bug when you deploy some service in AWS it has some region. Also, parameter store variables also created based on region. So you need to mention the region here. Else use https://www.serverless.com/ where you can handle it better. – Himanshu Joshi Apr 02 '22 at 16:36