Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Use a Ruby SDK generated by API Gateway for a REST API

Focus mode
Use a Ruby SDK generated by API Gateway for a REST API - Amazon API Gateway

The following procedure shows how to use a Ruby SDK generated by API Gateway.

Note

These instructions assume you already completed the instructions in Generate SDKs for REST APIs in API Gateway.

To install, instantiate, and call a Ruby SDK generated by API Gateway for a REST API
  1. Unzip the downloaded Ruby SDK file. The generated SDK source is shown as follows.

    Unzip the downloaded Ruby SDK file into a Ruby module

  2. Build a Ruby Gem from the generated SDK source, using the following shell commands in a terminal window:

    # change to /simplecalc-sdk directory cd simplecalc-sdk # build the generated gem gem build simplecalc-sdk.gemspec

    After this, simplecalc-sdk-1.0.0.gem becomes available.

  3. Install the gem:

    gem install simplecalc-sdk-1.0.0.gem
  4. Create a client application. Instantiate and initialize the Ruby SDK client in the app:

    require 'simplecalc-sdk' client = SimpleCalc::Client.new( http_wire_trace: true, retry_limit: 5, http_read_timeout: 50 )

    If the API has authorization of the AWS_IAM type is configured, you can include the caller's AWS credentials by supplying accessKey and secretKey during the initialization:

    require 'pet-sdk' client = Pet::Client.new( http_wire_trace: true, retry_limit: 5, http_read_timeout: 50, access_key_id: 'ACCESS_KEY', secret_access_key: 'SECRET_KEY' )
  5. Make API calls through the SDK in the app.

    Tip

    If you are not familiar with the SDK method call conventions, you can review the client.rb file in the generated SDK lib folder. The folder contains documentation of each supported API method call.

    To discover supported operations:

    # to show supported operations: puts client.operation_names

    This results in the following display, corresponding to the API methods of GET /?a={.}&b={.}&op={.}, GET /{a}/{b}/{op}, and POST /, plus a payload of the {a:"…", b:"…", op:"…"} format, respectively:

    [:get_api_root, :get_ab_op, :post_api_root]

    To invoke the GET /?a=1&b=2&op=+ API method, call the following the Ruby SDK method:

    resp = client.get_api_root({a:"1", b:"2", op:"+"})

    To invoke the POST / API method with a payload of {a: "1", b: "2", "op": "+"}, call the following Ruby SDK method:

    resp = client.post_api_root(input: {a:"1", b:"2", op:"+"})

    To invoke the GET /1/2/+ API method, call the following Ruby SDK method:

    resp = client.get_ab_op({a:"1", b:"2", op:"+"})

    The successful SDK method calls return the following response:

    resp : { result: { input: { a: 1, b: 2, op: "+" }, output: { c: 3 } } }
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.