1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iam
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/iam/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Creates an IAM role that is linked to a specific AWS service. The service
15// controls the attached policies and when the role can be deleted. This helps
16// ensure that the service is not broken by an unexpectedly changed or deleted
17// role, which could put your AWS resources into an unknown state. Allowing the
18// service to control the role helps improve service stability and proper cleanup
19// when a service and its role are no longer needed. For more information, see
20// Using Service-Linked Roles
21// (https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html)
22// in the IAM User Guide. To attach a policy to this service-linked role, you must
23// make the request using the AWS service that depends on this role.
24func (c *Client) CreateServiceLinkedRole(ctx context.Context, params *CreateServiceLinkedRoleInput, optFns ...func(*Options)) (*CreateServiceLinkedRoleOutput, error) {
25	if params == nil {
26		params = &CreateServiceLinkedRoleInput{}
27	}
28
29	result, metadata, err := c.invokeOperation(ctx, "CreateServiceLinkedRole", params, optFns, addOperationCreateServiceLinkedRoleMiddlewares)
30	if err != nil {
31		return nil, err
32	}
33
34	out := result.(*CreateServiceLinkedRoleOutput)
35	out.ResultMetadata = metadata
36	return out, nil
37}
38
39type CreateServiceLinkedRoleInput struct {
40
41	// The service principal for the AWS service to which this role is attached. You
42	// use a string similar to a URL but without the http:// in front. For example:
43	// elasticbeanstalk.amazonaws.com. Service principals are unique and
44	// case-sensitive. To find the exact service principal for your service-linked
45	// role, see AWS Services That Work with IAM
46	// (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html)
47	// in the IAM User Guide. Look for the services that have Yes in the Service-Linked
48	// Role column. Choose the Yes link to view the service-linked role documentation
49	// for that service.
50	//
51	// This member is required.
52	AWSServiceName *string
53
54	// A string that you provide, which is combined with the service-provided prefix to
55	// form the complete role name. If you make multiple requests for the same service,
56	// then you must supply a different CustomSuffix for each request. Otherwise the
57	// request fails with a duplicate role name error. For example, you could add -1 or
58	// -debug to the suffix. Some services do not support the CustomSuffix parameter.
59	// If you provide an optional suffix and the operation fails, try the operation
60	// again without the suffix.
61	CustomSuffix *string
62
63	// The description of the role.
64	Description *string
65}
66
67type CreateServiceLinkedRoleOutput struct {
68
69	// A Role object that contains details about the newly created role.
70	Role *types.Role
71
72	// Metadata pertaining to the operation's result.
73	ResultMetadata middleware.Metadata
74}
75
76func addOperationCreateServiceLinkedRoleMiddlewares(stack *middleware.Stack, options Options) (err error) {
77	err = stack.Serialize.Add(&awsAwsquery_serializeOpCreateServiceLinkedRole{}, middleware.After)
78	if err != nil {
79		return err
80	}
81	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpCreateServiceLinkedRole{}, middleware.After)
82	if err != nil {
83		return err
84	}
85	if err = addSetLoggerMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
89		return err
90	}
91	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
92		return err
93	}
94	if err = addResolveEndpointMiddleware(stack, options); err != nil {
95		return err
96	}
97	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
98		return err
99	}
100	if err = addRetryMiddlewares(stack, options); err != nil {
101		return err
102	}
103	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
107		return err
108	}
109	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
110		return err
111	}
112	if err = addClientUserAgent(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addOpCreateServiceLinkedRoleValidationMiddleware(stack); err != nil {
122		return err
123	}
124	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateServiceLinkedRole(options.Region), middleware.Before); err != nil {
125		return err
126	}
127	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
128		return err
129	}
130	if err = addResponseErrorMiddleware(stack); err != nil {
131		return err
132	}
133	if err = addRequestResponseLogging(stack, options); err != nil {
134		return err
135	}
136	return nil
137}
138
139func newServiceMetadataMiddleware_opCreateServiceLinkedRole(region string) *awsmiddleware.RegisterServiceMetadata {
140	return &awsmiddleware.RegisterServiceMetadata{
141		Region:        region,
142		ServiceID:     ServiceID,
143		SigningName:   "iam",
144		OperationName: "CreateServiceLinkedRole",
145	}
146}
147