Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (7k points)

I am trying to fetch all instance types for the EC2 from EC2 SDK JSON

const instanceEnums = require('aws-sdk/apis/ec2-2016-11-15.normal.json');

function getAllTypes(property) {

   return instanceEnums.shapes[property].enum;

}

getAllTypes('InstanceType')

But I get an error :

cannot find module aws-sdk/apis/ec2-2016-11-15.normal.json

I realized, the installed SDK/module does not include the .normal.json file.

Any body knows how to access the files from the apis folder?

1 Answer

0 votes
by (31.9k points)

You can download .normal.json directly from github and use it as follows:

const axios = require('axios');

const url = 'https://raw.githubusercontent.com/aws/aws-sdk-js/master/apis/ec2-2016-11-15.normal.json';

const getAllTypes = (() => {

  const loadApi = axios.get(url);

  return (property) => loadApi.then(response => {

    return response.data.shapes[property].enum

  })

})();

getAllTypes('InstanceType').then((types) => {

  console.log(types);

});

Are you interested to learn AWS ? Then check out AWS Certification Training Course. 

Related questions

0 votes
1 answer
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...