Last active
July 5, 2017 13:50
-
-
Save juliedavila/98623cc76ece2495efcb4a6289889028 to your computer and use it in GitHub Desktop.
Template snippet allowing for regions to be shown as a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Template } from 'meteor/templating'; | |
Template.registerHelper("regionsList", function(){ | |
if(Template.instance().regionList){ | |
return Template.instance().regionList.get() | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ValidatedMethod } from 'meteor/mdg:validated-method'; | |
import { Meteor } from 'meteor/meteor'; | |
import { EC2, Credentials } from 'aws-sdk' | |
// You should NOT store your access keys in your source code, this is purely for demo purposes. | |
// Store them in your meteor settings or expose them as environment variables. | |
const AWS_ACCESS_KEY = 'XXXYOUR_AWS_API_ACCESS_KEYXXX' | |
const AWS_SECRET_KEY = 'XXYOUR_AWS_API_SECRET_KEYXXX' | |
export const getAwsRegions = new ValidatedMethod({ | |
name: 'getAwsRegions', | |
validate: null, | |
run(){ | |
const AwsAuth = new Credentials(AWS_ACCESS_KEY, AWS_SECRET_KEY); | |
const ec2 = new EC2({credentials: AwsAuth, region: 'us-east-1'}); | |
let regions = []; | |
let resp = ec2.describeRegions({},function(err, data){ | |
if(err){ | |
return err; | |
} | |
}).promise(); | |
result = resp.then(function(data) { | |
return data.Regions.map(function(regionObj){return regionObj.RegionName}) | |
}).catch(function(err) { | |
throw new Meteor.Error('get-regions-error', err.message) | |
}); | |
return result; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ReactiveVar } from 'meteor/reactive-var'; | |
Template.MyTemplate.onCreated(function(){ | |
this.bucketList = new ReactiveVar([]); | |
}) | |
Template.MyTemplate.onRendered(function(){ | |
Meteor.call('getAwsRegions', function(error, result){ | |
if(error){ | |
Bert.alert({ | |
title: error.error, | |
message: error.reason , | |
type: 'danger', | |
}); | |
console.log(error); | |
} | |
template.regionList.set(result); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="MyTemplate"> | |
<div> | |
{{#each region in regionsList }} | |
<div> | |
<h4>{{region}}</h4> | |
</div> | |
{{/each}} | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment