diff --git a/moto/iam/models.py b/moto/iam/models.py index 73d58b996..25bfca05f 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -309,6 +309,7 @@ class Role(BaseModel): permissions_boundary, description, tags, + max_session_duration, ): self.id = role_id self.name = name @@ -320,6 +321,7 @@ class Role(BaseModel): self.tags = tags self.description = description self.permissions_boundary = permissions_boundary + self.max_session_duration = max_session_duration @property def created_iso_8601(self): @@ -938,9 +940,10 @@ class IAMBackend(BaseBackend): role.description = role_description return role - def update_role(self, role_name, role_description): + def update_role(self, role_name, role_description, max_session_duration): role = self.get_role(role_name) role.description = role_description + role.max_session_duration = max_session_duration return role def detach_role_policy(self, policy_arn, role_name): @@ -1059,6 +1062,7 @@ class IAMBackend(BaseBackend): permissions_boundary, description, tags, + max_session_duration, ): role_id = random_resource_id() if permissions_boundary and not self.policy_arn_regex.match( @@ -1084,6 +1088,7 @@ class IAMBackend(BaseBackend): permissions_boundary, description, clean_tags, + max_session_duration, ) self.roles[role_id] = role return role diff --git a/moto/iam/responses.py b/moto/iam/responses.py index ea14bef0f..45bd28c36 100644 --- a/moto/iam/responses.py +++ b/moto/iam/responses.py @@ -182,6 +182,7 @@ class IamResponse(BaseResponse): permissions_boundary = self._get_param("PermissionsBoundary") description = self._get_param("Description") tags = self._get_multi_param("Tags.member") + max_session_duration = self._get_param("MaxSessionDuration", 3600) role = iam_backend.create_role( role_name, @@ -190,6 +191,7 @@ class IamResponse(BaseResponse): permissions_boundary, description, tags, + max_session_duration, ) template = self.response_template(CREATE_ROLE_TEMPLATE) return template.render(role=role) @@ -258,7 +260,8 @@ class IamResponse(BaseResponse): def update_role(self): role_name = self._get_param("RoleName") description = self._get_param("Description") - role = iam_backend.update_role(role_name, description) + max_session_duration = self._get_param("MaxSessionDuration", 3600) + role = iam_backend.update_role(role_name, description, max_session_duration) template = self.response_template(UPDATE_ROLE_TEMPLATE) return template.render(role=role) @@ -1189,9 +1192,12 @@ CREATE_ROLE_TEMPLATE = """