{"id":14110102,"url":"https://github.com/fog/fog-aws","last_synced_at":"2025-08-01T09:32:59.935Z","repository":{"id":25219394,"uuid":"28643625","full_name":"fog/fog-aws","owner":"fog","description":"Module for the 'fog' gem to support Amazon Web Services http://aws.amazon.com/","archived":false,"fork":false,"pushed_at":"2025-06-20T14:44:40.000Z","size":15906,"stargazers_count":303,"open_issues_count":16,"forks_count":354,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-07-19T22:13:46.748Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"geemus"}},"created_at":"2014-12-30T20:04:47.000Z","updated_at":"2025-07-16T20:50:29.000Z","dependencies_parsed_at":"2023-01-14T13:31:09.263Z","dependency_job_id":"39429f62-c727-413e-af6a-1a2a06537f18","html_url":"https://github.com/fog/fog-aws","commit_stats":{"total_commits":910,"total_committers":205,"mean_commits":4.439024390243903,"dds":0.8131868131868132,"last_synced_commit":"69798e288512fa3dc078b578d1e12f811db38dfe"},"previous_names":[],"tags_count":90,"template":false,"template_full_name":null,"purl":"pkg:github/fog/fog-aws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fog%2Ffog-aws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fog%2Ffog-aws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fog%2Ffog-aws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fog%2Ffog-aws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fog","download_url":"https://codeload.github.com/fog/fog-aws/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fog%2Ffog-aws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266204224,"owners_count":23892357,"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-08-14T10:02:39.753Z","updated_at":"2025-08-01T09:32:59.908Z","avatar_url":"https://github.com/fog.png","language":"Ruby","funding_links":["https://github.com/sponsors/geemus"],"categories":["Ruby"],"sub_categories":[],"readme":"# Fog::Aws\n\n![Gem Version](https://badge.fury.io/rb/fog-aws.svg)\n[![Build Status](https://github.com/fog/fog-aws/actions/workflows/ci.yml/badge.svg)](https://github.com/fog/fog-aws/actions/workflows/ci.yml)\n[![Test Coverage](https://codeclimate.com/github/fog/fog-aws/badges/coverage.svg)](https://codeclimate.com/github/fog/fog-aws)\n[![Code Climate](https://codeclimate.com/github/fog/fog-aws.svg)](https://codeclimate.com/github/fog/fog-aws)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'fog-aws'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install fog-aws\n\n## Usage\n\nBefore you can use fog-aws, you must require it in your application:\n\n```ruby\nrequire 'fog/aws'\n```\n\nSince it's a bad practice to have your credentials in source code, you should load them from default fog configuration file: ```~/.fog```. This file could look like this:\n\n```\ndefault:\n  aws_access_key_id:     \u003cYOUR_ACCESS_KEY_ID\u003e\n  aws_secret_access_key: \u003cYOUR_SECRET_ACCESS_KEY\u003e\n```\n\n### EC2\n\n#### Connecting to the EC2 Service:\n\n```ruby\nec2 = Fog::Compute.new :provider =\u003e 'AWS', :region =\u003e 'us-west-2'\n```\n\nYou can review all the requests available with this service using ```#requests``` method:\n\n```ruby\nec2.requests # =\u003e [:allocate_address, :assign_private_ip_addresses, :associate_address, ...]\n```\n\n#### Launch an EC2 on-demand instance:\n\n```ruby\nresponse = ec2.run_instances(\n  \"ami-23ebb513\",\n  1,\n  1,\n  \"InstanceType\"  =\u003e \"t1.micro\",\n  \"SecurityGroup\" =\u003e \"ssh\",\n  \"KeyName\"       =\u003e \"miguel\"\n)\ninstance_id = response.body[\"instancesSet\"].first[\"instanceId\"] # =\u003e \"i-02db5af4\"\ninstance = ec2.servers.get(instance_id)\ninstance.wait_for { ready? }\nputs instance.public_ip_address # =\u003e \"356.300.501.20\"\n```\n\n#### Terminate an EC2 instance:\n\n```ruby\ninstance = ec2.servers.get(\"i-02db5af4\")\ninstance.destroy\n```\n\n`Fog::AWS` is more than EC2 since it supports many services provided by AWS. The best way to learn and to know about how many services are supported is to take a look at the source code. To review the tests directory and to play with the library in ```bin/console``` can be very helpful resources as well.\n\n### S3\n\n#### Connecting to the S3 Service:\n\n```ruby\ns3 = Fog::Storage.new(provider: 'AWS', region: 'eu-central-1')\n```\n\n#### Creating a file:\n\n```ruby\ndirectory = s3.directories.new(key: 'gaudi-portal-dev')\nfile = directory.files.create(key: 'user/1/Gemfile', body: File.open('Gemfile'), tags: 'Org-Id=1\u0026Service-Name=My-Service')\n```\n\n#### Listing files:\n\n```ruby\ndirectory = s3.directories.get('gaudi-portal-dev', prefix: 'user/1/')\ndirectory.files\n```\n**Warning!** `s3.directories.get` retrieves and caches meta data for the first 10,000 objects in the bucket, which can be very expensive. When possible use `s3.directories.new`.\n\n#### Generating a URL for a file:\n\n```ruby\ndirectory.files.new(key: 'user/1/Gemfile').url(Time.now + 60)\n```\n\n##### Generate download URL\nYou should pass an option argument that contains the `query` key with `response-content-disposition` inside indicating that is an attachment and the filename to be used when downloaded.\n\n```ruby\noptions = {\n  query: {\n    'response-content-disposition' =\u003e \"attachment; filename=#{key}\"\n  }\n}\n\ndirectory.files.new(key: 'user/1/Gemfile').url(Time.now + 60, options)\n```\n\n\n##### Controlling credential refresh time with IAM authentication\n\nWhen using IAM authentication with\n[temporary security credentials](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html),\ngenerated S3 pre-signed URLs\n[only last as long as the temporary credential](https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html).\n\nGenerating the URLs in the following manner will return a URL\nthat will not last as long as its requested expiration time if\nthe remainder of the authentication token lifetime was shorter.\n\n```ruby\ns3 = Fog::Storage.new(provider: 'AWS', use_iam_profile: true)\ndirectory = s3.directories.get('gaudi-portal-dev', prefix: 'user/1/')\n\ndirectory.files.new(key: 'user/1/Gemfile').url(Time.now + 60)\n```\n\nBy default the temporary credentials in use are refreshed only within the last\n15 seconds of its expiration time. The URL requested with 60 seconds lifetime\nusing the above example will only remain valid for 15 seconds in the worst case.\n\nThe problem can be avoided by refreshing the token early and often,\nby setting configuration `aws_credentials_refresh_threshold_seconds` (default: 15)\nwhich controls the time when the refresh must occur. It is expressed in seconds\nbefore the temporary credential's expiration time.\n\nThe following example can ensure pre-signed URLs last as long as 60 seconds\nby automatically refreshing the credentials when its remainder lifetime\nis lower than 60 seconds:\n\n```ruby\ns3 = Fog::Storage.new(\n  provider: 'AWS',\n  use_iam_profile: true,\n  aws_credentials_refresh_threshold_seconds: 60\n)\ndirectory = s3.directories.get('gaudi-portal-dev', prefix: 'user/1/')\n\ndirectory.files.new(key: 'user/1/Gemfile').url(Time.now + 60)\n```\n\n#### Copying a file\n\n```ruby\ndirectory = s3.directories.new(key: 'gaudi-portal-dev')\nfile = directory.files.get('user/1/Gemfile')\nfile.copy(\"target-bucket\", \"user/2/Gemfile.copy\")\n```\n\nTo speed transfers of large files, the `concurrency` option can be used\nto spawn multiple threads. Note that the file must be at least 5 MB for\nmultipart uploads to work. For example:\n\n```ruby\ndirectory = s3.directories.new(key: 'gaudi-portal-dev')\nfile = directory.files.get('user/1/Gemfile')\nfile.multipart_chunk_size = 10 * 1024 * 1024\nfile.concurrency = 10\nfile.copy(\"target-bucket\", \"user/2/Gemfile.copy\")\n```\n\n## Documentation\n\nSee the [online documentation](http://www.rubydoc.info/github/fog/fog-aws) for a complete API reference.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\n1. Fork it ( https://github.com/fog/fog-aws/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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffog%2Ffog-aws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffog%2Ffog-aws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffog%2Ffog-aws/lists"}