{"action":"created","issue":{"url":"https://api.github.com/repos/boto/boto3/issues/69","labels_url":"https://api.github.com/repos/boto/boto3/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/boto/boto3/issues/69/comments","events_url":"https://api.github.com/repos/boto/boto3/issues/69/events","html_url":"https://github.com/boto/boto3/pull/69","id":59165930,"number":69,"title":"Add profile_name option to sessions","user":{"login":"danielgtaylor","id":106826,"avatar_url":"https://avatars.githubusercontent.com/u/106826?v=3","gravatar_id":"","url":"https://api.github.com/users/danielgtaylor","html_url":"https://github.com/danielgtaylor","followers_url":"https://api.github.com/users/danielgtaylor/followers","following_url":"https://api.github.com/users/danielgtaylor/following{/other_user}","gists_url":"https://api.github.com/users/danielgtaylor/gists{/gist_id}","starred_url":"https://api.github.com/users/danielgtaylor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielgtaylor/subscriptions","organizations_url":"https://api.github.com/users/danielgtaylor/orgs","repos_url":"https://api.github.com/users/danielgtaylor/repos","events_url":"https://api.github.com/users/danielgtaylor/events{/privacy}","received_events_url":"https://api.github.com/users/danielgtaylor/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/boto/boto3/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":{"login":"danielgtaylor","id":106826,"avatar_url":"https://avatars.githubusercontent.com/u/106826?v=3","gravatar_id":"","url":"https://api.github.com/users/danielgtaylor","html_url":"https://github.com/danielgtaylor","followers_url":"https://api.github.com/users/danielgtaylor/followers","following_url":"https://api.github.com/users/danielgtaylor/following{/other_user}","gists_url":"https://api.github.com/users/danielgtaylor/gists{/gist_id}","starred_url":"https://api.github.com/users/danielgtaylor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielgtaylor/subscriptions","organizations_url":"https://api.github.com/users/danielgtaylor/orgs","repos_url":"https://api.github.com/users/danielgtaylor/repos","events_url":"https://api.github.com/users/danielgtaylor/events{/privacy}","received_events_url":"https://api.github.com/users/danielgtaylor/received_events","type":"User","site_admin":false},"milestone":null,"comments":7,"created_at":"2015-02-26T23:59:20Z","updated_at":"2015-02-27T22:19:53Z","closed_at":"2015-02-27T21:36:18Z","pull_request":{"url":"https://api.github.com/repos/boto/boto3/pulls/69","html_url":"https://github.com/boto/boto3/pull/69","diff_url":"https://github.com/boto/boto3/pull/69.diff","patch_url":"https://github.com/boto/boto3/pull/69.patch"},"body":"This change makes it possible to create a session using a profile name, which\r\nwas previously only possible via an environment variable. It allows you to\r\ncreate clients and resources from any number of sessions using any number of\r\nprofiles.\r\n\r\nGiven that we have the following `~/.aws/credentials`:\r\n\r\n```ini\r\n[default]\r\naws_access_key_id = DEFAULT\r\naws_secret_access_key = SECRET1\r\n\r\n[dev]\r\naws_access_key_id = DEV\r\naws_secret_access_key = SECRET2\r\n\r\n[prod]\r\naws_access_key_id = PROD\r\naws_secret_access_key = SECRET3\r\n```\r\n\r\nYou can do the following:\r\n\r\n```python\r\nimport boto3.session\r\n\r\ndev = boto3.session.Session(profile_name='dev')\r\nprod = boto3.session.Session(profile_name='prod')\r\n\r\nfor session in [dev, prod]:\r\n    print('Profile: ' + session.profile)\r\n    s3 = session.resource('s3')\r\n    for bucket in s3.buckets.all():\r\n        print(bucket.name)\r\n    print('')\r\n```\r\n\r\nIt is also possible to setup the default session with a profile:\r\n\r\n```python\r\nimport boto3\r\n\r\nboto3.setup_default_session(profile_name='dev')\r\n\r\ns3 = boto3.resource('s3')\r\n```\r\n\r\nAnd of course you can still use the environment variable:\r\n\r\n```bash\r\n$ BOTO_DEFAULT_PROFILE=dev ipython\r\n>>> import boto3\r\n>>> s3dev = boto3.resource('s3')\r\n```\r\n\r\nOnce a session is created, the profile is immutable. The `profile_name`\r\nproperty is provided for convenience and just surfaces the underlying\r\nBotocore session's profile property.\r\n\r\nWhy not provide a profile name to the `client` and `resource` methods?\r\nCurrently there is no easy way to clone a session, and the behavior of\r\ncreating a new blank session (from one which may have customizations)\r\nleads to possibly unintended side-effects like clients without the\r\nproper event handlers registered. This would be an additive change\r\nshould we want to revisit in the future. At this point, the change\r\nin this commit provides a way for Boto 3 users to use multiple profiles\r\nwithout resorting to creating their own Botocore sessions.\r\n\r\nI'm definitely open to suggestions and counter-arguments.\r\n\r\ncc @jamesls @kyleknap "},"comment":{"url":"https://api.github.com/repos/boto/boto3/issues/comments/76483373","html_url":"https://github.com/boto/boto3/pull/69#issuecomment-76483373","issue_url":"https://api.github.com/repos/boto/boto3/issues/69","id":76483373,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2015-02-27T22:19:53Z","updated_at":"2015-02-27T22:19:53Z","body":"\n[![Coverage Status](https://coveralls.io/builds/2013047/badge)](https://coveralls.io/builds/2013047)\n\nChanges Unknown when pulling **2a10ea6cb9183e60cde0ba9d3e34fa962f8fe811 on session-profile** into ** on develop**.\n"}}