Examples of Ruby on rails + aws congnito
<p>I am building a <code>rails 5</code> app that is deployed on <code>heroku</code>.
I want to use <code>AWS congnito</code> to achieve single sign on, but there are not enough example to implement it.
I am using <code>devise</code> for authentication. Now my goal is to put my all users on <code>AWS cognito</code> and authenticate them from my rails App.</p>

<p>This is the only resource i found on <a href="http://docs.aws.amazon.com/sdkforruby/api/Aws/CognitoIdentity/Client.html" rel="noreferrer">AWS congnito with rails</a>, I am looking for some example application or a link to tools or ruby API document to achieve this.</p>

<p>Please Help. </p>

<blockquote>
  <p>Update On basis Of Bala Answer</p>
</blockquote>

<pre><code>require 'aws-sdk'

ENV['AWS_ACCESS_KEY_ID'] = 'XXXXXXXXXXXXXXXXX'
ENV['AWS_SECRET_ACCESS_KEY'] = 'XXXX+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
region_name = 'us-east-1'
endpoint = 'cognito-idp.us-east-1.amazonaws.com'

client = Aws::CognitoIdentityProvider::Client.new(
  region: region_name
)


resp = client.admin_create_user({
  user_pool_id: "us-east-1_iD7xNHj0x", # required
  username: "Test", # required
  user_attributes: [
    {
      name: "email", # required
      value: "sachin.singh@example.com",
    },
  ],
  validation_data: [
    {
      name: "Email", # required
      value: "AttributeValueType",
    },
  ],
  temporary_password: "PasswordType",
  force_alias_creation: false,
  message_action: "RESEND", # accepts RESEND, SUPPRESS
  desired_delivery_mediums: ["EMAIL"], # accepts SMS, EMAIL
})
</code></pre>

<blockquote>
  <p>Error stack trace</p>
</blockquote>

<pre><code>home/sachin/.rvm/gems/ruby-2.1.5@global/gems/aws-sdk-core-2.6.38/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call': User does not exist. (Aws::CognitoIdentityProvider::Errors::UserNotFoundException)
    from /home/sachin/.rvm/gems/ruby-2.1.5@global/gems/aws-sdk-core-2.6.38/lib/aws-sdk-core/plugins/idempotency_token.rb:18:in `call'
    from /home/sachin/.rvm/gems/ruby-2.1.5@global/gems/aws-sdk-core-2.6.38/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call'
    from /home/sachin/.rvm/gems/ruby-2.1.5@global/gems/aws-sdk-core-2.6.38/lib/seahorse/client/plugins/response_target.rb:21:in `call'
    from /home/sachin/.rvm/gems/ruby-2.1.5@global/gems/aws-sdk-core-2.6.38/lib/seahorse/client/request.rb:70:in `send_request'
    from /home/sachin/.rvm/gems/ruby-2.1.5@global/gems/aws-sdk-core-2.6.38/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods'
    from aws_cognito.rb:20:in `&lt;main&gt;'
</code></pre>

<blockquote>
  <p>Update 2</p>
</blockquote>

<pre><code>resp = client.admin_initiate_auth({
  user_pool_id: "us-east-1_uKM", # required
  client_id: "3g766413826eul9kre28qne4f", # required
  auth_flow: "ADMIN_NO_SRP_AUTH",
  auth_parameters: {
    "EMAIL" =&gt; "kapil.sachdev@metacube.com",
    "PASSWORD" =&gt; "Ibms#1234"
  }
})
</code></pre>