For AWS, how do you set tags to a resource with the ruby aws-sdk?
amazon-ec2, amazon-web-services, ruby
Solution
The simplest way to tag an EC2 resource is it use the #tags method:
ec2.snapshots["snapshot-id"].tags["tag"] = "value"
If you want a handle to the tag object created, you can still use the TagCollection#create method. It expects the first param to be a resource:
tag = ec2.tags.create(ec2.snapshots['snapshot-id'], 'tag') # no tag value
tag = ec2.tags.create(ec2.snapshots['snapshot-id'], 'tag', 'value')
Problem
I'm pretty new to using Amazon's ruby-sdk (gem install aws-sdk), and am stuck trying to simply create a tag for a snapshotted resource. Here's what I'm doing: ``` ec2.tags.create(:resource_id => "snap-7d3aa701", :key => "My Test Tag", :value => "My test value") ArgumentError: wrong number of arguments (1 for 2) ``` Note, ec2 = AWS::EC2.new (after I set my credentials). Any ideas what I'm doing wrong? I haven't been able to find a single example online of using the ruby aws-sdk for tagging.