Ruby: Request temporary AWS credentials from Token Vending Machine - ruby

While setting up a Token Vending Machine is well documented, I am having a hard time finding sample code for requesting temporary credentials using Ruby (on Rails).
How would one go about interacting with the TVM using Ruby (on Rails)? Is there any sample code that lays out the process of making a request to a TVM and obtaining temporary credentials to access the various AWS services?

Bart: after a bit of digging, I found the following link for AWS with Ruby: Getting Started. This link is a bit of a walk-through for getting set up, and contains some example code to demonstrate how to authenticate and such.
You can also refer to the AWS SDK for Ruby, which has code examples, browse the GitHub Source Code Repository for the SDK, and check out the Ruby AWS Developer Center, Ruby AWS Developer Forums, and Ruby AWS FAQs.
I would also familiarize myself with the AWS SDK API Reference which is an invaluable reference guide for doing exactly what you're looking for.
EDIT: A few more resources:
You might take a look at the following file: TokenVendingMachinePolicy.json which contains a configuration to be used in conjunction with the AWS TVM process. While this file is used by a Java project, the JSON should be re-usable for your purposes.
You may also get some headway by taking a look at the rest of the code (while written in Java) which utilizes that file.
The major pieces appear to be:
DeviceAuthentication.java
UserAuthentication.java
GetTokenServlet.java
If you start with these 3 files, I think you should be able to make some headway in translation to Ruby.

It looks like Amazon also has a Ruby SDK with a section on STS. Hope this helps others in the future.

Related

How would I update the title of a YouTube livebroadcast via a Bash script?

I have a YouTube channel that has a number of live broadcasts throughout the week, I am just looking for a way for the Title and Description to be updated via a crontab.
I have see seen the following link. https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/update
To be honest I cant make any sense of it.
Any help offered greatly appreciated.
You're in front of a non-trivial API, but that should not discourage you to go ahead with it.
I'd recommend Python as implementation language: go use the Google's APIs Client Library for Python.
Basically, this library is of good quality and (compared to other client libraries) simple to use. It will, for example, insulate you from having to deal explicitly with REST API calls, JSON and the like. Your code will also work under both GNU/Linux and Windows.
You may begin your journey by reading the official getting started docs: Python Quickstart and YouTube Live Streaming API Overview. Then I recommend absorbing these two important documents: Life of a Broadcast and Understanding Broadcasts and Streams.
Then go read, understand and run the following sample program from Google: create_broadcast.py. Of course, you'll have to adapt that code to your use case.
You'll have to exercise patience and perseverance (since I imply that you have no prior experience using the YouTube Data API). Using this API will pay off to you at the end of your (programming) journey.
A special mention: for to be able to call the live streaming APIs you will first need to get acquainted with the things related to the so-called OAuth 2.0 authorization and authentication: Implementing OAuth 2.0 Authentication. There's an official document that you need absorb: OAuth 2.0 for Mobile & Desktop Apps.
A few more references: the live streaming API has an official documentation too. The main site documenting the client library is: Google API Client Library for Python Docs. Its source is public, to be found within the client library's public repo under the directory docs.
Also useful is to see the YouTube Data API's list of all instance methods.

Can Dexie syncable be used with an api server vs directly with a database

I have seen the sample projects on your website for Dexie.Syncable such as sync-server and sync-client and they all seem to write to a datbase directly vs interacting with a web api. I am looking for a little help in where to get started beyond the examples on the website. The api I am trying to write a gateway for is dreamfactory
Also it looks like version 2 beta has had many improvements to Dexie.Syncable
I would recommend to build a new server-project based on either WebSocketSyncServer.js or the github repo of sync-server. However, I cannot give the details on how to call REST APIs instead of working directly towards database or memory. I would suggest using ES2016 async/await since your API calls are asynchronic.
Maybe you could try getting more help on https://github.com/nponiros/sync_server by filing an issue there.

Starting an AWS Instance with API, AUTHPARAMS

I am trying to start an AMI using
https://ec2.amazonaws.com/
?Action=StartInstances
&InstanceId.1=i-10a64379
&AUTHPARAMS
Like documentadion says here but I am unable to find what AUTHPARAMS refers to.
Thanks
As Steffen notes, the API is much easier to use than the direct REST calls (especially the reasonably new Command Line Interface -- which is much more lightweight, and arguably easier to use as a result of the JSON integration, than the original by-product Command Line Tools)
...but if you are determined:
It's somewhat buried in the documentation, but the following links seem to lead us toward an answer:
1) the high level description of the "AUTHPARAMS" (as referenced frequently in the API documentation.)
AuthParams
The parameters that are required to authenticate a
Conditional request. Contains:
AWSAccessKeyID
SignatureVersion
Timestamp
Signature
Default: None
Required: Conditional
2) a step by step outline of the parameters needed for a REST request:
3) the detailed outline of the method to derive the "signature" for the "AUTHPARAMS"
This is the example in the documentation (I've added newlines to make it easier to read)
https://elasticmapreduce.amazonaws.com?
AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&
Action=DescribeJobFlows&
SignatureMethod=HmacSHA256&
SignatureVersion=2&
Timestamp=2011-10-03T15%3A19%3A30&
Version=2009-03-31&
Signature=i91nKc4PWAt0JJIdXwz9HxZCJDdiy6cf%2FMj6vPxyYIs%3D
4) Additionally there is some general information here about signatures
First and foremost, to interact with the Amazon EC2 API, I highly recommend to use one of the available SDKs if possible - this will make your life much simpler, especially when also interacting with any of the many other AWS Products and Solutions over time, insofar the SDKs relief you from tedious boilerplate code and also harmonize cross services API usage in general and the authentication process you are asking about in particular.
Now, if you really want/need to handle authentication yourself, you'll find the required information in Query API Authentication, which links to Signature Version 2 Signing Process in turn (the signature version changes over time, which is one of the topics the SDKs abstract away for example).

What is the simplest way for me to use Google's APIs?

Currently, I'm trying to get a list of advertisers (See http://code.google.com/apis/gan/v1beta1/advertisers/list.html) with my relationship status from Google's API.
I'm using Ruby and the 'google-api-client' gem and I'm writing this as an automated task. I've suddenly been thrust in to their world of browser windows, shell scripts, and every nut and bolt of OAuth2. I think I'm using the solution for a much different problem - accessing the data of people coming to your website. I just want MY data. Surely there's a much simpler way for me to get it?
Many other affiliate networks give me a REST service (or butchering thereof) and secret params/headers for auth.
I've registered myself as user of my 'device'. My app can now access my data!
I followed the instructions here:
https://code.google.com/apis/accounts/docs/OAuth2ForDevices.html
Is this the correct/best way to do it? I am unsure.

What gem should I use to work with AWS

I'm currently writing an application in ruby on rails that uses AWS. I see two options for gems, aws-sdk and fog. Fog seems to support almost all of the AWS services except for sns(which I wanted to use :/) and has mock services for testing not to mention you can change out for rackspace or a different provider rather easily. Is there any big reason why I should use AWS's sdk? It supports sns, but not rds and does not come with mocking.
If I'm missing something please let me know as I am new to this.
Thanks in advance.
You may also want to checkout rightaws though unfortunately it doesn't have support for sns either. It was one of the first libraries available and provides support for most of the functionalities. However, fog is releasing new versions more often and is catching up quickly and is a bit more high level. The aws_sdk was only released recently and the main reason to go with it is that it comes from Amazon itself and will likely become the standard. This is why we included it in rubystack. We expect that people will provide higher level libraries that will build on top of it.
aws-sdk supports SNS but does not mock the services. It does hoever provide basic stubbing:
AWS.stub!
This causes all service requests to "do nothing" and return "empty responses". It is used extensively inside the specs provided with the gem. This is is not the same as mocking a service but it can be a useful testing aid.

Resources