|
| 1 | +// smithy-typescript generated code |
| 2 | +import { EndpointParameterInstructions, getEndpointPlugin } from "@smithy/middleware-endpoint"; |
| 3 | +import { getSerdePlugin } from "@smithy/middleware-serde"; |
| 4 | +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http"; |
| 5 | +import { Command as $Command } from "@smithy/smithy-client"; |
| 6 | +import { |
| 7 | + FinalizeHandlerArguments, |
| 8 | + Handler, |
| 9 | + HandlerExecutionContext, |
| 10 | + HttpHandlerOptions as __HttpHandlerOptions, |
| 11 | + MetadataBearer as __MetadataBearer, |
| 12 | + MiddlewareStack, |
| 13 | + SerdeContext as __SerdeContext, |
| 14 | + SMITHY_CONTEXT_KEY, |
| 15 | +} from "@smithy/types"; |
| 16 | + |
| 17 | +import { CreateSessionOutput, CreateSessionOutputFilterSensitiveLog, CreateSessionRequest } from "../models/models_0"; |
| 18 | +import { de_CreateSessionCommand, se_CreateSessionCommand } from "../protocols/Aws_restXml"; |
| 19 | +import { S3ClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../S3Client"; |
| 20 | + |
| 21 | +/** |
| 22 | + * @public |
| 23 | + */ |
| 24 | +export { __MetadataBearer, $Command }; |
| 25 | +/** |
| 26 | + * @public |
| 27 | + * |
| 28 | + * The input for {@link CreateSessionCommand}. |
| 29 | + */ |
| 30 | +export interface CreateSessionCommandInput extends CreateSessionRequest {} |
| 31 | +/** |
| 32 | + * @public |
| 33 | + * |
| 34 | + * The output of {@link CreateSessionCommand}. |
| 35 | + */ |
| 36 | +export interface CreateSessionCommandOutput extends CreateSessionOutput, __MetadataBearer {} |
| 37 | + |
| 38 | +/** |
| 39 | + * @public |
| 40 | + * <p>Creates a session that establishes temporary security credentials to support fast authentication and authorization for the Zonal endpoint APIs on directory buckets. |
| 41 | + * For more information about Zonal endpoint APIs that include the Availability Zone in the request endpoint, see |
| 42 | + * <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-APIs.html">S3 Express One Zone APIs</a> in the <i>Amazon S3 User Guide</i>. |
| 43 | + * </p> |
| 44 | + * <p>To make Zonal endpoint API requests on a directory bucket, use the <code>CreateSession</code> |
| 45 | + * API operation. Specifically, you grant <code>s3express:CreateSession</code> permission to a |
| 46 | + * bucket in a bucket policy or an IAM identity-based policy. Then, you use IAM credentials to make the |
| 47 | + * <code>CreateSession</code> API request on the bucket, which returns temporary security |
| 48 | + * credentials that include the access key ID, secret access key, session token, and |
| 49 | + * expiration. These credentials have associated permissions to access the Zonal endpoint APIs. After |
| 50 | + * the session is created, you don’t need to use other policies to grant permissions to each |
| 51 | + * Zonal endpoint API individually. Instead, in your Zonal endpoint API requests, you sign your requests by |
| 52 | + * applying the temporary security credentials of the session to the request headers and |
| 53 | + * following the SigV4 protocol for authentication. You also apply the session token to the |
| 54 | + * <code>x-amz-s3session-token</code> request header for authorization. Temporary security |
| 55 | + * credentials are scoped to the bucket and expire after 5 minutes. After the expiration time, |
| 56 | + * any calls that you make with those credentials will fail. You must use IAM credentials |
| 57 | + * again to make a <code>CreateSession</code> API request that generates a new set of |
| 58 | + * temporary credentials for use. Temporary credentials cannot be extended or refreshed beyond |
| 59 | + * the original specified interval.</p> |
| 60 | + * <p>If you use Amazon Web Services SDKs, SDKs handle the session token refreshes automatically to avoid |
| 61 | + * service interruptions when a session expires. We recommend that you use the Amazon Web Services SDKs to |
| 62 | + * initiate and manage requests to the CreateSession API. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-optimizing-performance-guidelines-design-patterns.html#s3-express-optimizing-performance-session-authentication">Performance guidelines and design patterns</a> in the |
| 63 | + * <i>Amazon S3 User Guide</i>.</p> |
| 64 | + * <note> |
| 65 | + * <ul> |
| 66 | + * <li> |
| 67 | + * <p>You must make requests for this API operation to the Zonal endpoint. These endpoints support virtual-hosted-style requests in the format <code>https://<i>bucket_name</i>.s3express-<i>az_id</i>.<i>region</i>.amazonaws.com</code>. Path-style requests are not supported. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-Regions-and-Zones.html">Regional and Zonal endpoints</a> in the |
| 68 | + * <i>Amazon S3 User Guide</i>.</p> |
| 69 | + * </li> |
| 70 | + * <li> |
| 71 | + * <p> |
| 72 | + * <b> |
| 73 | + * <code>CopyObject</code> API operation</b> - Unlike other Zonal endpoint APIs, the <code>CopyObject</code> API operation doesn't use the temporary security credentials returned from the <code>CreateSession</code> API operation for authentication and authorization. For information about authentication and authorization of the <code>CopyObject</code> API operation on directory buckets, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html">CopyObject</a>.</p> |
| 74 | + * </li> |
| 75 | + * <li> |
| 76 | + * <p> |
| 77 | + * <b> |
| 78 | + * <code>HeadBucket</code> API operation</b> - Unlike other Zonal endpoint APIs, the <code>HeadBucket</code> API operation doesn't use the temporary security credentials returned from the <code>CreateSession</code> API operation for authentication and authorization. For information about authentication and authorization of the <code>HeadBucket</code> API operation on directory buckets, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html">HeadBucket</a>.</p> |
| 79 | + * </li> |
| 80 | + * </ul> |
| 81 | + * </note> |
| 82 | + * <dl> |
| 83 | + * <dt>Permissions</dt> |
| 84 | + * <dd> |
| 85 | + * <p>To obtain temporary security credentials, you must create a bucket policy or an IAM identity-based policy that |
| 86 | + * grants <code>s3express:CreateSession</code> permission to the bucket. In a |
| 87 | + * policy, you can have the <code>s3express:SessionMode</code> condition key to |
| 88 | + * control who can create a <code>ReadWrite</code> or <code>ReadOnly</code> session. |
| 89 | + * For more information about <code>ReadWrite</code> or <code>ReadOnly</code> |
| 90 | + * sessions, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateSession.html#API_CreateSession_RequestParameters"> |
| 91 | + * <code>x-amz-create-session-mode</code> |
| 92 | + * </a>. For example policies, see |
| 93 | + * <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-security-iam-example-bucket-policies.html">Example bucket policies for S3 Express One Zone</a> and <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-security-iam-identity-policies.html">Amazon Web Services Identity and Access Management (IAM) identity-based policies for S3 Express One Zone</a> in the |
| 94 | + * <i>Amazon S3 User Guide</i>. </p> |
| 95 | + * <p>To grant cross-account access to Zonal endpoint APIs, the bucket policy should also grant both accounts the <code>s3express:CreateSession</code> permission.</p> |
| 96 | + * </dd> |
| 97 | + * <dt>HTTP Host header syntax</dt> |
| 98 | + * <dd> |
| 99 | + * <p> |
| 100 | + * <b>Directory buckets </b> - The HTTP Host header syntax is <code> |
| 101 | + * <i>Bucket_name</i>.s3express-<i>az_id</i>.<i>region</i>.amazonaws.com</code>.</p> |
| 102 | + * </dd> |
| 103 | + * </dl> |
| 104 | + * @example |
| 105 | + * Use a bare-bones client and the command you need to make an API call. |
| 106 | + * ```javascript |
| 107 | + * import { S3Client, CreateSessionCommand } from "@aws-sdk/client-s3"; // ES Modules import |
| 108 | + * // const { S3Client, CreateSessionCommand } = require("@aws-sdk/client-s3"); // CommonJS import |
| 109 | + * const client = new S3Client(config); |
| 110 | + * const input = { // CreateSessionRequest |
| 111 | + * SessionMode: "ReadOnly" || "ReadWrite", |
| 112 | + * Bucket: "STRING_VALUE", // required |
| 113 | + * }; |
| 114 | + * const command = new CreateSessionCommand(input); |
| 115 | + * const response = await client.send(command); |
| 116 | + * // { // CreateSessionOutput |
| 117 | + * // Credentials: { // SessionCredentials |
| 118 | + * // AccessKeyId: "STRING_VALUE", // required |
| 119 | + * // SecretAccessKey: "STRING_VALUE", // required |
| 120 | + * // SessionToken: "STRING_VALUE", // required |
| 121 | + * // Expiration: new Date("TIMESTAMP"), // required |
| 122 | + * // }, |
| 123 | + * // }; |
| 124 | + * |
| 125 | + * ``` |
| 126 | + * |
| 127 | + * @param CreateSessionCommandInput - {@link CreateSessionCommandInput} |
| 128 | + * @returns {@link CreateSessionCommandOutput} |
| 129 | + * @see {@link CreateSessionCommandInput} for command's `input` shape. |
| 130 | + * @see {@link CreateSessionCommandOutput} for command's `response` shape. |
| 131 | + * @see {@link S3ClientResolvedConfig | config} for S3Client's `config` shape. |
| 132 | + * |
| 133 | + * @throws {@link NoSuchBucket} (client fault) |
| 134 | + * <p>The specified bucket does not exist.</p> |
| 135 | + * |
| 136 | + * @throws {@link S3ServiceException} |
| 137 | + * <p>Base exception class for all service exceptions from S3 service.</p> |
| 138 | + * |
| 139 | + */ |
| 140 | +export class CreateSessionCommand extends $Command< |
| 141 | + CreateSessionCommandInput, |
| 142 | + CreateSessionCommandOutput, |
| 143 | + S3ClientResolvedConfig |
| 144 | +> { |
| 145 | + public static getEndpointParameterInstructions(): EndpointParameterInstructions { |
| 146 | + return { |
| 147 | + DisableS3ExpressSessionAuth: { type: "staticContextParams", value: true }, |
| 148 | + Bucket: { type: "contextParams", name: "Bucket" }, |
| 149 | + ForcePathStyle: { type: "clientContextParams", name: "forcePathStyle" }, |
| 150 | + UseArnRegion: { type: "clientContextParams", name: "useArnRegion" }, |
| 151 | + DisableMultiRegionAccessPoints: { type: "clientContextParams", name: "disableMultiregionAccessPoints" }, |
| 152 | + Accelerate: { type: "clientContextParams", name: "useAccelerateEndpoint" }, |
| 153 | + UseGlobalEndpoint: { type: "builtInParams", name: "useGlobalEndpoint" }, |
| 154 | + UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" }, |
| 155 | + Endpoint: { type: "builtInParams", name: "endpoint" }, |
| 156 | + Region: { type: "builtInParams", name: "region" }, |
| 157 | + UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" }, |
| 158 | + }; |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * @public |
| 163 | + */ |
| 164 | + constructor(readonly input: CreateSessionCommandInput) { |
| 165 | + super(); |
| 166 | + } |
| 167 | + |
| 168 | + /** |
| 169 | + * @internal |
| 170 | + */ |
| 171 | + resolveMiddleware( |
| 172 | + clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>, |
| 173 | + configuration: S3ClientResolvedConfig, |
| 174 | + options?: __HttpHandlerOptions |
| 175 | + ): Handler<CreateSessionCommandInput, CreateSessionCommandOutput> { |
| 176 | + this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize)); |
| 177 | + this.middlewareStack.use(getEndpointPlugin(configuration, CreateSessionCommand.getEndpointParameterInstructions())); |
| 178 | + |
| 179 | + const stack = clientStack.concat(this.middlewareStack); |
| 180 | + |
| 181 | + const { logger } = configuration; |
| 182 | + const clientName = "S3Client"; |
| 183 | + const commandName = "CreateSessionCommand"; |
| 184 | + const handlerExecutionContext: HandlerExecutionContext = { |
| 185 | + logger, |
| 186 | + clientName, |
| 187 | + commandName, |
| 188 | + inputFilterSensitiveLog: (_: any) => _, |
| 189 | + outputFilterSensitiveLog: CreateSessionOutputFilterSensitiveLog, |
| 190 | + [SMITHY_CONTEXT_KEY]: { |
| 191 | + service: "AmazonS3", |
| 192 | + operation: "CreateSession", |
| 193 | + }, |
| 194 | + }; |
| 195 | + const { requestHandler } = configuration; |
| 196 | + return stack.resolve( |
| 197 | + (request: FinalizeHandlerArguments<any>) => |
| 198 | + requestHandler.handle(request.request as __HttpRequest, options || {}), |
| 199 | + handlerExecutionContext |
| 200 | + ); |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * @internal |
| 205 | + */ |
| 206 | + private serialize(input: CreateSessionCommandInput, context: __SerdeContext): Promise<__HttpRequest> { |
| 207 | + return se_CreateSessionCommand(input, context); |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * @internal |
| 212 | + */ |
| 213 | + private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<CreateSessionCommandOutput> { |
| 214 | + return de_CreateSessionCommand(output, context); |
| 215 | + } |
| 216 | +} |
0 commit comments