| 1 |
.. Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
|
| 3 |
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 |
| 4 |
International License (the "License"). You may not use this file except in compliance with the |
| 5 |
License. A copy of the License is located at http://creativecommons.org/licenses/by-nc-sa/4.0/. |
| 6 |
|
| 7 |
This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 8 |
either express or implied. See the License for the specific language governing permissions and |
| 9 |
limitations under the License. |
| 10 |
|
| 11 |
.. _aws-boto3-iam-examples-server-certs: |
| 12 |
|
| 13 |
|
| 14 |
#################################### |
| 15 |
Working with IAM server certificates |
| 16 |
#################################### |
| 17 |
|
| 18 |
This Python example shows you how to carry out basic tasks in managing server certificates for HTTPS connections. |
| 19 |
|
| 20 |
The scenario |
| 21 |
============ |
| 22 |
|
| 23 |
To enable HTTPS connections to your website or application on AWS, you need an SSL/TLS server certificate. |
| 24 |
To use a certificate that you obtained from an external provider with your website or application on AWS, |
| 25 |
you must upload the certificate to IAM or import it into AWS Certificate Manager. |
| 26 |
|
| 27 |
In this example, python code is used to handle server certificates in IAM. The code uses the |
| 28 |
Amazon Web Services (AWS) SDK for Python to manage server certificates using these methods of the |
| 29 |
IAM client class: |
| 30 |
|
| 31 |
* `get_paginator('list_server_certificates') <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.update_access_key>`_. |
| 32 |
|
| 33 |
* `get_server_certificate <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.get_server_certificate>`_. |
| 34 |
|
| 35 |
* `update_server_certificate <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.update_server_certificate>`_. |
| 36 |
|
| 37 |
* `delete_server_certificate <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.delete_server_certificate>`_. |
| 38 |
|
| 39 |
All the example code for the Amazon Web Services (AWS) SDK for Python is available `here on GitHub <https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/python/example_code>`_. |
| 40 |
|
| 41 |
For more information about server certificates, see `Working with Server Certificates <http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_server-certs.html>`_ |
| 42 |
in the *IAM User Guide*. |
| 43 |
|
| 44 |
Prerequisite tasks |
| 45 |
================= |
| 46 |
|
| 47 |
To set up and run this example, you must first configure your AWS credentials, as described in :doc:`quickstart`. |
| 48 |
|
| 49 |
List your server certificates |
| 50 |
============================= |
| 51 |
|
| 52 |
List the server certificates stored in IAM. If none exist, the action returns an empty list. |
| 53 |
|
| 54 |
The example below shows how to: |
| 55 |
|
| 56 |
* List server certificates using |
| 57 |
`get_paginator('list_server_certificates') <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.get_paginator>`_. |
| 58 |
|
| 59 |
For more information about paginators see, :doc:`paginators` |
| 60 |
|
| 61 |
Example |
| 62 |
------- |
| 63 |
|
| 64 |
.. code-block:: python |
| 65 |
|
| 66 |
import boto3 |
| 67 |
|
| 68 |
# Create IAM client |
| 69 |
iam = boto3.client('iam') |
| 70 |
|
| 71 |
# List server certificates through the pagination interface |
| 72 |
paginator = iam.get_paginator('list_server_certificates') |
| 73 |
for response in paginator.paginate(): |
| 74 |
print(response['ServerCertificateMetadataList']) |
| 75 |
|
| 76 |
Get a server certificate |
| 77 |
======================== |
| 78 |
|
| 79 |
Get information about the specified server certificate stored in IAM. |
| 80 |
|
| 81 |
The example below shows how to: |
| 82 |
|
| 83 |
* Get a server certificate using |
| 84 |
`get_server_certificate <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.get_server_certificate>`_. |
| 85 |
|
| 86 |
Example |
| 87 |
------- |
| 88 |
|
| 89 |
.. code-block:: python |
| 90 |
|
| 91 |
import boto3 |
| 92 |
|
| 93 |
|
| 94 |
# Create IAM client |
| 95 |
iam = boto3.client('iam') |
| 96 |
|
| 97 |
# Get the server certificate |
| 98 |
response = iam.get_server_certificate(ServerCertificateName='CERTIFICATE_NAME') |
| 99 |
print(response['ServerCertificate']) |
| 100 |
|
| 101 |
Update a server certificate |
| 102 |
=========================== |
| 103 |
|
| 104 |
Update the name and/or the path of the specified server certificate stored in IAM. |
| 105 |
|
| 106 |
The example below shows how to: |
| 107 |
|
| 108 |
* Update a server certificate using |
| 109 |
`update_server_certificate <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.update_server_certificate>`_. |
| 110 |
|
| 111 |
Example |
| 112 |
------- |
| 113 |
|
| 114 |
.. code-block:: python |
| 115 |
|
| 116 |
import boto3 |
| 117 |
|
| 118 |
# Create IAM client |
| 119 |
iam = boto3.client('iam') |
| 120 |
|
| 121 |
# Update the name of the server certificate |
| 122 |
iam.update_server_certificate( |
| 123 |
ServerCertificateName='CERTIFICATE_NAME', |
| 124 |
NewServerCertificateName='NEW_CERTIFICATE_NAME' |
| 125 |
) |
| 126 |
|
| 127 |
Delete a server certificate |
| 128 |
=========================== |
| 129 |
|
| 130 |
Delete the specified server certificate. |
| 131 |
|
| 132 |
The example below shows how to: |
| 133 |
|
| 134 |
* Delete a server certificate using |
| 135 |
`delete_server_certificate <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.delete_server_certificate>`_. |
| 136 |
|
| 137 |
Example |
| 138 |
------- |
| 139 |
|
| 140 |
.. code-block:: python |
| 141 |
|
| 142 |
import boto3 |
| 143 |
|
| 144 |
|
| 145 |
# Create IAM client |
| 146 |
iam = boto3.client('iam') |
| 147 |
|
| 148 |
# Delete the server certificate |
| 149 |
iam.delete_server_certificate( |
| 150 |
ServerCertificateName='CERTIFICATE_NAME' |
| 151 |
) |