What gem should I use to work with AWS - ruby

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.

Related

Supporting multiple versions of Kuberentes APIs in Go program

Kubernetes has a rapidly evolving API and I am trying to find best practices, recommendations, or really any kind of guidance about how to write Go software that gracefully handles supporting its evolving API and supports multiple versions simultaneously. I am sure I am not the first person to attempt this, but so far I have not found any guidance about Kubernetes specifically, and what I have read about polymorphism in Go has not inspired a great solution yet.
Kubernetes is written in Go and provides Go packages like k8s.io/api/extensions/v1beta1 and k8s.io/api/networking/v1beta1. Kubernetes resources, for example Ingress, are first released in one API group (extensions) and as they become more mature, get moved to another API group (networking) and can also change versions (e.g. go from v1beta1 to plain v1). Kubernetes also provides k8s.io/client-go for interacting with a Kubernetes cluster.
I am an experienced object-oriented (and other types of) programmer, but fairly new to Go and completely new to the Kubernetes packages. What I want to accomplish is a program architecture that allows me to write code once and have it work on any version of the Kubernetes resource, at least as long as the resource contains all the features I care about. In a typical object-oriented environment, I would create a base Ingress class and have all these various versions derive from it, and package up operations so that I could just work on Ingress everywhere. My sense is that Go intends for people to take a different approach, and in any case there are complications because of the client/server aspect.
Client/server and APIs
My Go program is a client of the Kubernetes server. Various version of the server will support various version of the Kubernetes API, and therefor various versions of the Ingress resource. So my first problem is that I have to do something like this to get a list of all the Ingresses:
ingressesExt, err := il.kubeClient.ExtensionsV1beta1().Ingresses(namespace).List(metav1.ListOptions{})
ingressesNet, err := il.kubeClient.NetworkingV1beta1().Ingresses(namespace).List(metav1.ListOptions{})
I have to gracefully handle errors about the API not being supported. Because the return types are different, AFAIK there is no unified interface where I can just make one call and get the results in a single list. It seems like this is the sort of thing someone should have solved and provided a solution for, but so far I have not found anything.
Type conversion
I also have to find some way to merge ingressesExt and ingressesNet into a single usable list, with an eye toward maintainability/extensibility now that Ingress has graduated to NetworkingV1.
Kubernetes utilities
I see that Kubernetes provides a lot of auto-generated code and utilities, but I have not found a lot of documentation about how to use them. For example, Ingress has functions like
DeepCopy
Marshal
XXX_DiscardUnknown
XXX_Merge
XXX_Unmarshal
Maybe I can use these to do the type conversion? Combine marshal, unmarshall, discard, and merge somehow to take the data from on version and import it into another?
Questions
Hopefully you see the issue and understand what I am trying to achieve.
Are there packages from Kubernetes or other open source authors that make some progress in unifying the APIs like I need?
Are any of the Kubernetes auto-generated functions meant for general use (as opposed to internal use) and helpful to my challenge? I have not found documentation for any but DeepCopy.
What is the "Go way" of abstracting out the differences between the various versions of the Ingress object such that I can write the rest of the code to work on any version? Keep in mind that I may need to make another API call for further processing, in which case I would need to know the concrete type of the object and select the right API call. It is not obvious to me that client-go provides any support for such auto-selection of API calls.

Whether to use googleapis or google-cloud library for node js

I see there are two available libraries. I am wondering what are the differences? Are they both officially maintained by Google?
https://www.npmjs.com/package/googleapis
https://www.npmjs.com/package/google-cloud
Yes both are maintained by Google. googleapis covers all these APIs (drive, calendar, admin sdk, maps, etc) whereas google-cloud covers the cloud platform stuff like bigquery, datastore, cloud storage, bigtable, pub/sub, etc. There appears to be overlap and I don't know which one is better for a particular service. Will be playing with cloud storage and admin sdk here soon though :)
The answer is found here.
From the reference, the #google-cloud library is recommended as it has the following benefits:
In some cases, gives you performance benefits by using gRPC. You can find out more in the gRPC APIs section below.
#googleapis " has autogenerated interface code that may not be as idiomatic as our newer libraries."
Personally, I think if you are using non-cloud APIs like Gmail, Calendar, etc, it may be more worth it to use just the Google APIs library for syntactic consistency.
One thing I noticed is that the #google-cloud library didn't allow the same authentication method that I like using with #googleapis:
const { google } = require('googleapis');
new google.auth.JWT(client_email, null, private_key, [
'https://www.googleapis.com/auth/cloud-platform'
]);

Considering Google Compute Engine to supplement our AWS stack, some comparison questions

We're exploring using GCE alongside out AWS deployment and I've a few questions coming from AWS.
It doesn't seem like the GCE Load Balancers support SSL (as in encrypting http traffic into https via the load balancer). I saw in the docs that its something that's coming .. does anyone know any good workarounds and possibly the timelines for actual support of this?
We use SQS on AWS a fair bit, and would like to use something simillar on GCE. There looks like there is Task Queues, but we've had a lot of trouble making them work in Ruby, for various issues, the docs seem somewhat lacking even trying to test them out in the builtin "try it out" tool. Does anyone have experience with having them work that could point us to a) a working ruby client library for it b) perhaps more complete docs (we have not even been able to issue a single authenticated request to them)
PubSub, we use SNS on AWS, and would like something simillar on GCE. Is PubSub the answer? It seems like its in invitation only beta right now? Any idea how we can get in and play with it?
Thank you.

Ruby: Request temporary AWS credentials from Token Vending Machine

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.

Ruby Web Services

I'm contemplating creating a web application using a Ruby on Rails/MySQL stack and I am wondering what capabilities are available around web services and SOAP. Is there a capability within the framework or does it require an extension and if so what?
Rails opted for REST over SOAP:
It’ll probably come as no surprise
that Rails has picked a side in the
SOAP vs REST debate. Unless you
absolutely have to use SOAP for
integration purposes, we strongly
discourage you from doing so. As a
naturally extension of that, we’ve
pulled ActionWebService from the
default bundle. It’s only a gem
install actionwebservice away, but it
sends an important message none the
less.
Still, if you must use SOAP, there's always soap4r, but it only supports SOAP 1.1. A better option might be WSF/Ruby. Mark Thomas has an example controller to help you get up and running.
Rails has opted for REST over SOAP in the default framework. It's not hard to go the SOAP route if you want to, though.
I don't recommend soap4r - as of a few months ago, anyway, it wasn't production quality. The updated version of ActionWebService has worked much better for me.
The old way in Rails was to use the Action Web Service framework. The preferred way now is to use the ActiveResource framework for RESTful web services.

Resources