AWS Open Source Blog

Announcing aws-record-generator

现已推出 aws-record-generator gem 开发人员预览版

aws-record-generator

We are happy to announce that the aws-record-generator gem is now in Developer Preview and available for you to try. This gem allows you to generate all of your aws-record models through the Rails commandline, and we anticipate that this should greatly simplify setup time in new projects!

What Is aws-record-generator?

aws-record-generator, which is dependent on Rails, provides command line generators that create aws-record compliant models.

Using aws-record-generator

You can download the aws-record-generator gem from RubyGems by including the –pre flag in a gem installation:

gem install 'aws-record-generator' --pre

You can also include it in your Gemfile. Do not include a version lock yet, so that bundler can find the pre-release version:

# Gemfile
gem 'aws-record-generator'

Generating a model

Model generation can be called from the rails command line such as:

rails g aws_record:model Dog name:hkey weight:int --table-config=primary:7-2 --required=name weight

More info on the valid parameters can be found in our GitHub repo.

The above command generates:

# app/models/dog.rb

require 'aws-record'

class Dog
  include Aws::Record

  string_attr :name, hash_key: true
  integer_attr :weight
  validates_presence_of :name, :weight
end
# db/table_config/dog_config.rb

require 'aws-record'

module ModelTableConfig
  def self.config
    Aws::Record::TableConfig.define do |t|
      t.model_class Dog

      t.read_capacity_units 7
      t.write_capacity_units 2
    end
  end
end

Your TableConfigurations can be run with a provided Rake task aws_record:migrate which migrates all configs in db/table_config to DynamoDB.

Note that generated aws-record models are not compatible with rails scaffolding at the moment.

Get Involved!

Please download the gem, give it a try, and let us know what you think. This project is a work in progress, so we welcome feature requests, bug reports, and information about the kinds of problems you’d like to solve by using this gem. And, as with other SDKs and tools we produce, we’d also be happy to look at contributions.

You can find the aws-record-generator-rails project on GitHub.

Please reach out and let us know what you think!

 

 

Yash Sharma

Yash Sharma

Yash Sharma is an intern on the AWS SDK for Ruby team this summer, and will be a Junior at the University of Illinois at Urbana-Champaign this coming Fall.