1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package lambda
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/lambda/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Invokes a Lambda function. You can invoke a function synchronously (and wait for
15// the response), or asynchronously. To invoke a function asynchronously, set
16// InvocationType to Event. For synchronous invocation
17// (https://docs.aws.amazon.com/lambda/latest/dg/invocation-sync.html), details
18// about the function response, including errors, are included in the response body
19// and headers. For either invocation type, you can find more information in the
20// execution log
21// (https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions.html) and
22// trace (https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html). When an
23// error occurs, your function may be invoked multiple times. Retry behavior varies
24// by error type, client, event source, and invocation type. For example, if you
25// invoke a function asynchronously and it returns an error, Lambda executes the
26// function up to two more times. For more information, see Retry Behavior
27// (https://docs.aws.amazon.com/lambda/latest/dg/retries-on-errors.html). For
28// asynchronous invocation
29// (https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html), Lambda
30// adds events to a queue before sending them to your function. If your function
31// does not have enough capacity to keep up with the queue, events may be lost.
32// Occasionally, your function may receive the same event multiple times, even if
33// no error occurs. To retain events that were not processed, configure your
34// function with a dead-letter queue
35// (https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#dlq). The
36// status code in the API response doesn't reflect function errors. Error codes are
37// reserved for errors that prevent your function from executing, such as
38// permissions errors, limit errors
39// (https://docs.aws.amazon.com/lambda/latest/dg/limits.html), or issues with your
40// function's code and configuration. For example, Lambda returns
41// TooManyRequestsException if executing the function would cause you to exceed a
42// concurrency limit at either the account level
43// (ConcurrentInvocationLimitExceeded) or function level
44// (ReservedFunctionConcurrentInvocationLimitExceeded). For functions with a long
45// timeout, your client might be disconnected during synchronous invocation while
46// it waits for a response. Configure your HTTP client, SDK, firewall, proxy, or
47// operating system to allow for long connections with timeout or keep-alive
48// settings. This operation requires permission for the lambda:InvokeFunction
49// (https://docs.aws.amazon.com/IAM/latest/UserGuide/list_awslambda.html) action.
50func (c *Client) Invoke(ctx context.Context, params *InvokeInput, optFns ...func(*Options)) (*InvokeOutput, error) {
51	if params == nil {
52		params = &InvokeInput{}
53	}
54
55	result, metadata, err := c.invokeOperation(ctx, "Invoke", params, optFns, addOperationInvokeMiddlewares)
56	if err != nil {
57		return nil, err
58	}
59
60	out := result.(*InvokeOutput)
61	out.ResultMetadata = metadata
62	return out, nil
63}
64
65type InvokeInput struct {
66
67	// The name of the Lambda function, version, or alias. Name formats
68	//
69	// * Function
70	// name - my-function (name-only), my-function:v1 (with alias).
71	//
72	// * Function ARN -
73	// arn:aws:lambda:us-west-2:123456789012:function:my-function.
74	//
75	// * Partial ARN -
76	// 123456789012:function:my-function.
77	//
78	// You can append a version number or alias to
79	// any of the formats. The length constraint applies only to the full ARN. If you
80	// specify only the function name, it is limited to 64 characters in length.
81	//
82	// This member is required.
83	FunctionName *string
84
85	// Up to 3583 bytes of base64-encoded data about the invoking client to pass to the
86	// function in the context object.
87	ClientContext *string
88
89	// Choose from the following options.
90	//
91	// * RequestResponse (default) - Invoke the
92	// function synchronously. Keep the connection open until the function returns a
93	// response or times out. The API response includes the function response and
94	// additional data.
95	//
96	// * Event - Invoke the function asynchronously. Send events that
97	// fail multiple times to the function's dead-letter queue (if it's configured).
98	// The API response only includes a status code.
99	//
100	// * DryRun - Validate parameter
101	// values and verify that the user or role has permission to invoke the function.
102	InvocationType types.InvocationType
103
104	// Set to Tail to include the execution log in the response.
105	LogType types.LogType
106
107	// The JSON that you want to provide to your Lambda function as input.
108	Payload []byte
109
110	// Specify a version or alias to invoke a published version of the function.
111	Qualifier *string
112}
113
114type InvokeOutput struct {
115
116	// The version of the function that executed. When you invoke a function with an
117	// alias, this indicates which version the alias resolved to.
118	ExecutedVersion *string
119
120	// If present, indicates that an error occurred during function execution. Details
121	// about the error are included in the response payload.
122	FunctionError *string
123
124	// The last 4 KB of the execution log, which is base64 encoded.
125	LogResult *string
126
127	// The response from the function, or an error object.
128	Payload []byte
129
130	// The HTTP status code is in the 200 range for a successful request. For the
131	// RequestResponse invocation type, this status code is 200. For the Event
132	// invocation type, this status code is 202. For the DryRun invocation type, the
133	// status code is 204.
134	StatusCode int32
135
136	// Metadata pertaining to the operation's result.
137	ResultMetadata middleware.Metadata
138}
139
140func addOperationInvokeMiddlewares(stack *middleware.Stack, options Options) (err error) {
141	err = stack.Serialize.Add(&awsRestjson1_serializeOpInvoke{}, middleware.After)
142	if err != nil {
143		return err
144	}
145	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpInvoke{}, middleware.After)
146	if err != nil {
147		return err
148	}
149	if err = addSetLoggerMiddleware(stack, options); err != nil {
150		return err
151	}
152	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
153		return err
154	}
155	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
156		return err
157	}
158	if err = addResolveEndpointMiddleware(stack, options); err != nil {
159		return err
160	}
161	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
162		return err
163	}
164	if err = addRetryMiddlewares(stack, options); err != nil {
165		return err
166	}
167	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
168		return err
169	}
170	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
171		return err
172	}
173	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
174		return err
175	}
176	if err = addClientUserAgent(stack); err != nil {
177		return err
178	}
179	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
180		return err
181	}
182	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
183		return err
184	}
185	if err = addOpInvokeValidationMiddleware(stack); err != nil {
186		return err
187	}
188	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opInvoke(options.Region), middleware.Before); err != nil {
189		return err
190	}
191	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
192		return err
193	}
194	if err = addResponseErrorMiddleware(stack); err != nil {
195		return err
196	}
197	if err = addRequestResponseLogging(stack, options); err != nil {
198		return err
199	}
200	return nil
201}
202
203func newServiceMetadataMiddleware_opInvoke(region string) *awsmiddleware.RegisterServiceMetadata {
204	return &awsmiddleware.RegisterServiceMetadata{
205		Region:        region,
206		ServiceID:     ServiceID,
207		SigningName:   "lambda",
208		OperationName: "Invoke",
209	}
210}
211