Amazon Cognito Identity Provider examples using SDK for Ruby - Amazon SDK for Ruby
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Amazon Cognito Identity Provider examples using SDK for Ruby

The following code examples show you how to perform actions and implement common scenarios by using the Amazon SDK for Ruby with Amazon Cognito Identity Provider.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.

Get started

The following code examples show how to get started using Amazon Cognito.

SDK for Ruby
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

require 'aws-sdk-cognitoidentityprovider' require 'logger' # CognitoManager is a class responsible for managing AWS Cognito operations # such as listing all user pools in the current AWS account. class CognitoManager def initialize(client) @client = client @logger = Logger.new($stdout) end # Lists and prints all user pools associated with the AWS account. def list_user_pools paginator = @client.list_user_pools(max_results: 10) user_pools = [] paginator.each_page do |page| user_pools.concat(page.user_pools) end if user_pools.empty? @logger.info('No Cognito user pools found.') else user_pools.each do |user_pool| @logger.info("User pool ID: #{user_pool.id}") @logger.info("User pool name: #{user_pool.name}") @logger.info("User pool status: #{user_pool.status}") @logger.info('---') end end end end if $PROGRAM_NAME == __FILE__ cognito_client = Aws::CognitoIdentityProvider::Client.new manager = CognitoManager.new(cognito_client) manager.list_user_pools end
  • For API details, see ListUserPools in Amazon SDK for Ruby API Reference.

Topics