AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to retrieve the specified SSH public key.

# Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of # the License is located at # # # # or in the "license" file accompanying this file. This file is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import boto3 user_name = 'your-name' # Create IAM client iam = boto3.client('iam') ssh_public_keys_response = iam.list_ssh_public_keys( UserName = user_name, MaxItems = 100, ) # Get SSH public key for ssh_public_key in ssh_public_keys_response['SSHPublicKeys']: ssh_public_key = ssh_public_key['SSHPublicKeyId'] ssh_public_key_response = iam.get_ssh_public_key( UserName = user_name, SSHPublicKeyId = ssh_public_key, Encoding = 'SSH', ) print(ssh_public_key_response['SSHPublicKey']['SSHPublicKeyBody'])

Sample Details

Service: iam

Last tested:

Author: jschwarzwalder (AWS)

Type: full-example

On this page: