Skip to content

Commit

Permalink
feat(client-lambda): This release adds a new Lambda InvokeWithRespons…
Browse files Browse the repository at this point in the history
…eStream API to support streaming Lambda function responses. The release also adds a new InvokeMode parameter to Function Url APIs to control whether the response will be streamed or buffered.
  • Loading branch information
awstools committed Apr 7, 2023
1 parent b0cd150 commit 1543d4c
Show file tree
Hide file tree
Showing 15 changed files with 1,542 additions and 205 deletions.
8 changes: 8 additions & 0 deletions clients/client-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,14 @@ InvokeAsync

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/classes/invokeasynccommand.html) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/interfaces/invokeasynccommandinput.html) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/interfaces/invokeasynccommandoutput.html)

</details>
<details>
<summary>
InvokeWithResponseStream
</summary>

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/classes/invokewithresponsestreamcommand.html) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/interfaces/invokewithresponsestreamcommandinput.html) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-lambda/interfaces/invokewithresponsestreamcommandoutput.html)

</details>
<details>
<summary>
Expand Down
3 changes: 3 additions & 0 deletions clients/client-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"@aws-sdk/client-sts": "*",
"@aws-sdk/config-resolver": "*",
"@aws-sdk/credential-provider-node": "*",
"@aws-sdk/eventstream-serde-browser": "*",
"@aws-sdk/eventstream-serde-config-resolver": "*",
"@aws-sdk/eventstream-serde-node": "*",
"@aws-sdk/fetch-http-handler": "*",
"@aws-sdk/hash-node": "*",
"@aws-sdk/invalid-dependency": "*",
Expand Down
62 changes: 62 additions & 0 deletions clients/client-lambda/src/Lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ import {
} from "./commands/GetRuntimeManagementConfigCommand";
import { InvokeAsyncCommand, InvokeAsyncCommandInput, InvokeAsyncCommandOutput } from "./commands/InvokeAsyncCommand";
import { InvokeCommand, InvokeCommandInput, InvokeCommandOutput } from "./commands/InvokeCommand";
import {
InvokeWithResponseStreamCommand,
InvokeWithResponseStreamCommandInput,
InvokeWithResponseStreamCommandOutput,
} from "./commands/InvokeWithResponseStreamCommand";
import { ListAliasesCommand, ListAliasesCommandInput, ListAliasesCommandOutput } from "./commands/ListAliasesCommand";
import {
ListCodeSigningConfigsCommand,
Expand Down Expand Up @@ -540,6 +545,12 @@ export class Lambda extends LambdaClient {
* Apache Kafka</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html">
* Amazon DocumentDB</a>
* </p>
* </li>
* </ul>
* <p>The following error handling options are available only for stream sources (DynamoDB and Kinesis):</p>
* <ul>
Expand Down Expand Up @@ -602,6 +613,12 @@ export class Lambda extends LambdaClient {
* Apache Kafka</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html#docdb-configuration">
* Amazon DocumentDB</a>
* </p>
* </li>
* </ul>
*/
public createEventSourceMapping(
Expand Down Expand Up @@ -1679,6 +1696,39 @@ export class Lambda extends LambdaClient {
}
}

/**
* @public
* <p>Configure your Lambda functions to stream response payloads back to clients. For more information, see <a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html">Configuring a Lambda function to stream responses</a>.</p>
*/
public invokeWithResponseStream(
args: InvokeWithResponseStreamCommandInput,
options?: __HttpHandlerOptions
): Promise<InvokeWithResponseStreamCommandOutput>;
public invokeWithResponseStream(
args: InvokeWithResponseStreamCommandInput,
cb: (err: any, data?: InvokeWithResponseStreamCommandOutput) => void
): void;
public invokeWithResponseStream(
args: InvokeWithResponseStreamCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: InvokeWithResponseStreamCommandOutput) => void
): void;
public invokeWithResponseStream(
args: InvokeWithResponseStreamCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: InvokeWithResponseStreamCommandOutput) => void),
cb?: (err: any, data?: InvokeWithResponseStreamCommandOutput) => void
): Promise<InvokeWithResponseStreamCommandOutput> | void {
const command = new InvokeWithResponseStreamCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* @public
* <p>Returns a list of <a href="https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html">aliases</a>
Expand Down Expand Up @@ -2573,6 +2623,12 @@ export class Lambda extends LambdaClient {
* Apache Kafka</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html">
* Amazon DocumentDB</a>
* </p>
* </li>
* </ul>
* <p>The following error handling options are available only for stream sources (DynamoDB and Kinesis):</p>
* <ul>
Expand Down Expand Up @@ -2635,6 +2691,12 @@ export class Lambda extends LambdaClient {
* Apache Kafka</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html#docdb-configuration">
* Amazon DocumentDB</a>
* </p>
* </li>
* </ul>
*/
public updateEventSourceMapping(
Expand Down
24 changes: 22 additions & 2 deletions clients/client-lambda/src/LambdaClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// smithy-typescript generated code
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@aws-sdk/config-resolver";
import {
EventStreamSerdeInputConfig,
EventStreamSerdeResolvedConfig,
resolveEventStreamSerdeConfig,
} from "@aws-sdk/eventstream-serde-config-resolver";
import { getContentLengthPlugin } from "@aws-sdk/middleware-content-length";
import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@aws-sdk/middleware-endpoint";
import {
Expand Down Expand Up @@ -38,6 +43,7 @@ import {
Decoder as __Decoder,
Encoder as __Encoder,
EndpointV2 as __EndpointV2,
EventStreamSerdeProvider as __EventStreamSerdeProvider,
Hash as __Hash,
HashConstructor as __HashConstructor,
HttpHandlerOptions as __HttpHandlerOptions,
Expand Down Expand Up @@ -150,6 +156,10 @@ import {
} from "./commands/GetRuntimeManagementConfigCommand";
import { InvokeAsyncCommandInput, InvokeAsyncCommandOutput } from "./commands/InvokeAsyncCommand";
import { InvokeCommandInput, InvokeCommandOutput } from "./commands/InvokeCommand";
import {
InvokeWithResponseStreamCommandInput,
InvokeWithResponseStreamCommandOutput,
} from "./commands/InvokeWithResponseStreamCommand";
import { ListAliasesCommandInput, ListAliasesCommandOutput } from "./commands/ListAliasesCommand";
import {
ListCodeSigningConfigsCommandInput,
Expand Down Expand Up @@ -284,6 +294,7 @@ export type ServiceInputTypes =
| GetRuntimeManagementConfigCommandInput
| InvokeAsyncCommandInput
| InvokeCommandInput
| InvokeWithResponseStreamCommandInput
| ListAliasesCommandInput
| ListCodeSigningConfigsCommandInput
| ListEventSourceMappingsCommandInput
Expand Down Expand Up @@ -354,6 +365,7 @@ export type ServiceOutputTypes =
| GetRuntimeManagementConfigCommandOutput
| InvokeAsyncCommandOutput
| InvokeCommandOutput
| InvokeWithResponseStreamCommandOutput
| ListAliasesCommandOutput
| ListCodeSigningConfigsCommandOutput
| ListEventSourceMappingsCommandOutput
Expand Down Expand Up @@ -503,6 +515,11 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
*/
logger?: __Logger;

/**
* The function that provides necessary utilities for generating and parsing event stream
*/
eventStreamSerdeProvider?: __EventStreamSerdeProvider;

/**
* The {@link @aws-sdk/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
*/
Expand All @@ -520,6 +537,7 @@ type LambdaClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOptions
HostHeaderInputConfig &
AwsAuthInputConfig &
UserAgentInputConfig &
EventStreamSerdeInputConfig &
ClientInputEndpointParameters;
/**
* @public
Expand All @@ -539,6 +557,7 @@ type LambdaClientResolvedConfigType = __SmithyResolvedConfiguration<__HttpHandle
HostHeaderResolvedConfig &
AwsAuthResolvedConfig &
UserAgentResolvedConfig &
EventStreamSerdeResolvedConfig &
ClientResolvedEndpointParameters;
/**
* @public
Expand Down Expand Up @@ -635,8 +654,9 @@ export class LambdaClient extends __Client<
const _config_5 = resolveHostHeaderConfig(_config_4);
const _config_6 = resolveAwsAuthConfig(_config_5);
const _config_7 = resolveUserAgentConfig(_config_6);
super(_config_7);
this.config = _config_7;
const _config_8 = resolveEventStreamSerdeConfig(_config_7);
super(_config_8);
this.config = _config_8;
this.middlewareStack.use(getRetryPlugin(this.config));
this.middlewareStack.use(getContentLengthPlugin(this.config));
this.middlewareStack.use(getHostHeaderPlugin(this.config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export interface CreateEventSourceMappingCommandOutput extends EventSourceMappin
* Apache Kafka</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html">
* Amazon DocumentDB</a>
* </p>
* </li>
* </ul>
* <p>The following error handling options are available only for stream sources (DynamoDB and Kinesis):</p>
* <ul>
Expand Down Expand Up @@ -133,6 +139,12 @@ export interface CreateEventSourceMappingCommandOutput extends EventSourceMappin
* Apache Kafka</a>
* </p>
* </li>
* <li>
* <p>
* <a href="https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html#docdb-configuration">
* Amazon DocumentDB</a>
* </p>
* </li>
* </ul>
* @example
* Use a bare-bones client and the command you need to make an API call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface CreateFunctionUrlConfigCommandOutput extends CreateFunctionUrlC
* ],
* MaxAge: Number("int"),
* },
* InvokeMode: "BUFFERED" || "RESPONSE_STREAM",
* };
* const command = new CreateFunctionUrlConfigCommand(input);
* const response = await client.send(command);
Expand Down
Loading

0 comments on commit 1543d4c

Please sign in to comment.