{"id":19889111,"url":"https://github.com/gree/aws_ro","last_synced_at":"2025-06-12T18:07:59.516Z","repository":{"id":62553866,"uuid":"54448702","full_name":"gree/aws_ro","owner":"gree","description":"\"Ruby Object\" or \"ReadOnly wrapper\" of AWS SDK for Ruby","archived":false,"fork":false,"pushed_at":"2019-11-07T06:19:57.000Z","size":57,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-26T03:11:03.567Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gree.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-22T05:46:27.000Z","updated_at":"2019-11-07T06:19:57.000Z","dependencies_parsed_at":"2022-11-03T04:30:49.318Z","dependency_job_id":null,"html_url":"https://github.com/gree/aws_ro","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/gree/aws_ro","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Faws_ro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Faws_ro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Faws_ro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Faws_ro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gree","download_url":"https://codeload.github.com/gree/aws_ro/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gree%2Faws_ro/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259518833,"owners_count":22870302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T18:09:11.016Z","updated_at":"2025-06-12T18:07:59.496Z","avatar_url":"https://github.com/gree.png","language":"Ruby","readme":"# AwsRo\n\nWrapper class of AWS Resource objects to enable to access properties more easily, more ruby-likely.\n\nThe targets of this library are small and medium scale AWS systems.\n\nNow supported only `Aws::EC2`, `Aws::ElasticLoadBalancing` and `Aws::ElasticLoadBalancingV2`.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'aws_ro', '~\u003e 1.1'\n```\n\nAnd then execute:\n\n    $ bundle\n\n\u003c!-- Or install it yourself as: --\u003e\n\n\u003c!--     $ gem install aws_ro --\u003e\n\n## Purpose of this gem\n\nEasy access to AWS Resources.\n\nFor example, I'd like to print values of 'MyTag' tag of instances which also contains 'MyEnv'=='develop' tag.\n\nBy using plain AWS SDK v2:\n\n```ruby\nclient = Aws::EC2::Client.new(some_options)\nres = client.describe_instances(filters: [{name: 'tag:MyEnv', values: ['develop']}, {name: 'tag:MyTag', values: ['*']}])\ninstances = res.reservations.flat_map(\u0026:instances)\ninstances.each do |i|\n  v = i.tags.find { |t| t.key == 'MyTag' }.value\n  puts \"ID: #{i.instance_id}, MyTag value: #{v}\"\nend\n```\n\nThis is not difficult, but is a little boring.\n\nOn the other hand, by using the `aws_ro` gem:\n\n```ruby\nrepo = AwsRo::EC2::Repository.new(some_options)\nrepo.tags({'MyEnv' =\u003e 'develop', 'MyTag' =\u003e '*'}).each do |i|\n  puts \"ID: #{i.instance_id}, MyTag value: #{i.my_tag}\"\nend\n```\n\nThis is simplified and keeping readability.\n\n\n## Usage\n### Basic Usage\n\n```ruby\nec2_options = { region: 'ap-northeast-1' }\nrepo = AwsRo::EC2::Repository.new(ec2_options)\ninstances = repo.running.tags({'MyAttrName' =\u003e 'MyValue'})\ninstances.each do |i|\n  puts \"#{i.name} #{i.public_ip_address}, #{i.my_attr_name}\"\nend\n```\n\n```ruby\nputs \"Print ALB rules and targets\"\noptions = { region: 'ap-northeast-1' }\nalbs = AwsRo::ElasticLoadBalancingV2::Repository.new(options).all\nalbs.all.each do |lb|\n  puts \"LoadBalancer: #{lb.name}\"\n  lb.listeners.each do |listener|\n    puts \"- #{listener.protocol} (#{listener.port})\"\n    listener.rules.each do |rule|\n      pattern = rule.default? ? '\u003cblank\u003e' : rule.path_pattern\n      puts \"  - #{pattern} : #{rule.forward_target_group.name} (#{rule.priority})\"\n    end\n  end\nend\n```\n\n### Classes\n#### class : `AwsRo::EC2::Repository`\n\nRepository is wrapper of EC2 client. It supports chainable queries to describe instances.\n\n\n##### Initialize\n```ruby\n# initialize with Aws::EC2::Client\nclient.class\n# =\u003e Aws::EC2::Client\nrepo = AwsRo::EC2::Repository.new(client)\n\n# initialize with option hash\nrepo = AwsRo::EC2::Repository.new({ region: 'ap-northeast-1' })\n```\n\n##### accessor\n\n```ruby\n# get raw client\nrepo.client\n# =\u003e Aws::EC2::Client\n```\n\n##### query methods\n\n```ruby\n# all running instance\nrepo.running.all? do |i|\n  i.class\n  # =\u003e AwsRo::EC2::Instance\n  i.state.name == 'running'\nend\n# =\u003e true\n\n# All query methods are chainable and return an `Array` like object.\n## list security group of running-public-instances\nrepo.running.filters([{name: 'ip-address', values: ['*'] }]).each do |i|\n  puts i.ec2.security_groups.map(\u0026:group_name)\nend\n\n## list my 'InUse' tag instances\nrepo.not_terminated.tags('InUse' =\u003e '*').map(\u0026:instance_id)\n# =\u003e [\"i-xxxxxxxx\",\"i-yyyyyyyy\",\"i-zzzzzzzz\", ...]\n```\n\n#### class : `AwsRo::EC2::Instance`\n\n`Instance` is wrapper of EC2 instace object.\n\n```ruby\nins = repo.all.first\n```\n\n##### static accessors\n\n```ruby\n# get raw ec2 object\nins.ec2\n# =\u003e Aws::EC2::Instance\n\n# some delegated methods and aliases for accessibility\n[\n  ins.instance_id == ins.ec2.instance_id,\n  ins.public_ip_address == ins.ec2.public_ip_address \u0026\u0026 ins.public_ip_address == ins.public_ip,\n  ins.private_ip_address == ins.ec2.private_ip_address \u0026\u0026 ins.private_ip == ins.private_ip,\n  ins.key_name == ins.ec2.key_name,\n  ins.state == ins.ec2.state\n].all?\n# =\u003e true\n```\n\n##### dynamic tag accessors\n\n```ruby\n# Instance#tags returns `Struct` of tags.\nins.tags.Name\n# =\u003e 'Value of Name tag'\nins.tags.roles\n# =\u003e 'staging, somerole'\nins.tags.xyz_enabled\n# =\u003e 'True'\n\n## and dynamically-defined reader methods are available as snake_case-ed tag name.\n## their values are stripped and formatted as `Array` if the value include whitespaces,\n## as boolean if the value like  boolean and when use `?`-terminated method.\nins.name\n# =\u003e 'Value of Name tag'\nins.roles\n# =\u003e ['staging', 'somerole']\nins.xyz_enabled?\n# =\u003e true\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\n1. Fork it ( https://github.com/gree/aws_ro/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## License\n\nThis library is distributed under the Apache License, version 2.0\n\n```no-highlight\ncopyright 2016. GREE, Inc. all rights reserved.\n\nlicensed under the apache license, version 2.0 (the \"license\");\nyou may not use this file except in compliance with the license.\nyou may obtain a copy of the license at\n\n    http://www.apache.org/licenses/license-2.0\n\nunless required by applicable law or agreed to in writing, software\ndistributed under the license is distributed on an \"as is\" basis,\nwithout warranties or conditions of any kind, either express or implied.\nsee the license for the specific language governing permissions and\nlimitations under the license.\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgree%2Faws_ro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgree%2Faws_ro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgree%2Faws_ro/lists"}