(DEV303) Touring Version 2 of the AWS SDK for Ruby | AWS re:Invent 2014

Click here to load reader

  • date post

    13-Jul-2015
  • Category

    Technology

  • view

    590
  • download

    8

Embed Size (px)

Transcript of (DEV303) Touring Version 2 of the AWS SDK for Ruby | AWS re:Invent 2014

  • November 13, 2014 | Las Vegas, NV

    Alex Wood, AWS SDK Team

  • aws-sdk

    aws-sdk-resources

    aws-sdk-core

  • aws-sdk-core

  • aw

    s-s

    dk-c

    ore

    Aws::S3::Client

    #list_objects GET bucket

    #put_object PUT bucket/object

    Aws::EC2::Client

    #describe_instances DescribeInstances

    #run_instances RunInstances

  • aws-sdk

    aws-sdk-resources

    aws-sdk-core

  • aws-sdk-resources

  • S3 Resource

    Bucket

    Object

    ObjectAcl ObjectVersion

    BucketAcl BucketLifecycle BucketLogging BucketNotification etc.

  • HTTPAws::S3::ClientMethodAws::S3

    Bucket #objects #list_objects GET /bucket

    Object

    #put #put_object PUT /bucket/key

    #etag #head_object HEAD /bucket/key

  • # Pick One:

    'aws-sdk', '2.0.6.pre'

    'aws-sdk-core'

  • # Pick One:

    'aws-sdk', '2.0.6.pre'

    'aws-sdk-core'

    # Can include V1 in the same project!

    'aws-sdk-v1'

  • "#{HOME}/.aws/credentials"

    INI format

    AWS CLI and other SDKs use same credentials

    "AWS_PROFILE" specifies credential profile

  • http://docs.aws.amazon.com/sdkforruby/api/frames.html

  • Pagination

    Waiters

  • AWS::EC2

    do

    end

  • AWS::EC2

    do

    end

    Aws::EC2::Resource

  • AWS::EC2

    do

    end

    Aws::EC2::Resource

  • Aws::EC2::Client

    filters:

    name: 'instance-state-name'

    values: 'running'

    do

    end

    instance_ids:

  • Aws::EC2::Client

    filters:

    name: 'instance-state-name'

    values: 'running'

    do

    end

    instance_ids:

    Aws::EC2::Resource

    filters:

    name: 'instance-state-name'

    values: 'running'

  • Object-oriented abstraction over clients

    Less hand-written code, more API abstractions

    Improved memoization

    Batching support

    Integrated with waiters and pagination

  • Resources

    Waiters

  • # v1 client - no built-in pagination

    AWS::S3::Client

    bucket_name:

    while do

    bucket_name:

    marker:

    :key

    end

  • # v2 client

    Aws::S3::Client

    bucket:

    do

    :key

  • # v2 resources

    Aws::S3::Resource

    do

    end

  • All responses automatically paginated, including client responses

    Includes helper methods

    Replaces many V1 higher level abstractions

  • Resources

    Pagination

  • # v1 high-level

    until do

    if :running

    else

    break if MAX_ATTEMPTS

    end

    end

  • # v1 high-level

    instance = ec2.instances[instance_id]

    until running do

    if instance.status == :running

    running = true

    else

    break if MAX_ATTEMPTS

    end

    end

  • # v2 client

    :instance_running instance_ids:

  • :object_exists

    bucket:

    key:

  • :object_exists

    bucket:

    key:

  • Polls client requests for success/failure states

    Configurable

    Can be used with base client and resources

  • http://bit.ly/awsevals

  • https://github.com/awslabs/todo-sample-app

    http://ruby.awsblog.com/blog/tag/TodoApp

  • 'aws-sdk-resources'

  • div id "subscription-forms"

    h3 h2

    div id "sms-form"

    p p

    div

    div id "email-form"

    p p

    div

    div

  • Subscribe to Task Updates

    Subscribe via SMS

    Subscribe via E-Mail

  • 'subscriptions/sms' => 'subscriptions#create_sms'

    'subscriptions/email' => 'subscriptions#create_email'

  • class SubscriptionsController ApplicationController

    def

    Subscription 'sms' 'subscription' 'endpoint'

    end

    def

    Subscription 'email' 'subscription' 'endpoint'

    end

    end

  • class Subscription

    def self

    Aws::SNS::Resource TOPIC_ARN

    end

    def self

    protocol: endpoint: if

    end

    def self

    message:

    :subject if

    end

    end

  • class Subscription

    def self.topic

    Aws::SNS::Resource TOPIC_ARN

    end

    def self.subscribe(protocol, endpoint)

    protocol: endpoint: if

    end

    def self.publish(message, subject = nil)

    opts = { message: message }

    opts[:subject] = subject if subject

    end

    end

  • def

    @task Task

    if @task

    Subscription "Created new task: #{@task.name}"

    "New Task Created"

    else

    :error "Task creation failed! #{print_errors(@task)}"

    end

    end

  • def create

    @task = Task.new(task_create_params)

    if @task.save

    Subscription "Created new task: #{@task.name}"

    "New Task Created"

    redirect_to tasks_path

    else

    flash[:error] = "Task creation failed! #{print_errors(@task)}"

    redirect_to tasks_path

    end

    end

  • https://github.com/aws/aws-sdk-core-ruby

    You can contribute bug fixes, resources, pagination support, waiters, and more!

    Bonus: Multiple SDKs use these definitions - wide impact!

    AWS CloudFormation resource definition was customer contributed:

    https://github.com/aws/aws-sdk-core-ruby/pull/127

  • http://ruby.awsblog.com/

  • http://bit.ly/awsevals