UNPKG

8.12 kBTypeScriptView Raw
1import { Resource } from '@aws-cdk/core';
2import { Construct } from 'constructs';
3import { IAuthorizer } from './authorizer';
4import { Integration } from './integration';
5import { MethodResponse } from './methodresponse';
6import { IModel } from './model';
7import { IRequestValidator, RequestValidatorOptions } from './requestvalidator';
8import { IResource } from './resource';
9import { IRestApi, RestApi } from './restapi';
10export interface MethodOptions {
11 /**
12 * A friendly operation name for the method. For example, you can assign the
13 * OperationName of ListPets for the GET /pets method.
14 */
15 readonly operationName?: string;
16 /**
17 * Method authorization.
18 * If the value is set of `Custom`, an `authorizer` must also be specified.
19 *
20 * If you're using one of the authorizers that are available via the {@link Authorizer} class, such as {@link Authorizer#token()},
21 * it is recommended that this option not be specified. The authorizer will take care of setting the correct authorization type.
22 * However, specifying an authorization type using this property that conflicts with what is expected by the {@link Authorizer}
23 * will result in an error.
24 *
25 * @default - open access unless `authorizer` is specified
26 */
27 readonly authorizationType?: AuthorizationType;
28 /**
29 * If `authorizationType` is `Custom`, this specifies the ID of the method
30 * authorizer resource.
31 * If specified, the value of `authorizationType` must be set to `Custom`
32 */
33 readonly authorizer?: IAuthorizer;
34 /**
35 * Indicates whether the method requires clients to submit a valid API key.
36 * @default false
37 */
38 readonly apiKeyRequired?: boolean;
39 /**
40 * The responses that can be sent to the client who calls the method.
41 * @default None
42 *
43 * This property is not required, but if these are not supplied for a Lambda
44 * proxy integration, the Lambda function must return a value of the correct format,
45 * for the integration response to be correctly mapped to a response to the client.
46 * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-settings-method-response.html
47 */
48 readonly methodResponses?: MethodResponse[];
49 /**
50 * The request parameters that API Gateway accepts. Specify request parameters
51 * as key-value pairs (string-to-Boolean mapping), with a source as the key and
52 * a Boolean as the value. The Boolean specifies whether a parameter is required.
53 * A source must match the format method.request.location.name, where the location
54 * is querystring, path, or header, and name is a valid, unique parameter name.
55 * @default None
56 */
57 readonly requestParameters?: {
58 [param: string]: boolean;
59 };
60 /**
61 * The models which describe data structure of request payload. When
62 * combined with `requestValidator` or `requestValidatorOptions`, the service
63 * will validate the API request payload before it reaches the API's Integration (including proxies).
64 * Specify `requestModels` as key-value pairs, with a content type
65 * (e.g. `'application/json'`) as the key and an API Gateway Model as the value.
66 *
67 * @example
68 *
69 * declare const api: apigateway.RestApi;
70 * declare const userLambda: lambda.Function;
71 *
72 * const userModel: apigateway.Model = api.addModel('UserModel', {
73 * schema: {
74 * type: apigateway.JsonSchemaType.OBJECT,
75 * properties: {
76 * userId: {
77 * type: apigateway.JsonSchemaType.STRING
78 * },
79 * name: {
80 * type: apigateway.JsonSchemaType.STRING
81 * }
82 * },
83 * required: ['userId']
84 * }
85 * });
86 * api.root.addResource('user').addMethod('POST',
87 * new apigateway.LambdaIntegration(userLambda), {
88 * requestModels: {
89 * 'application/json': userModel
90 * }
91 * }
92 * );
93 *
94 * @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-settings-method-request.html#setup-method-request-model
95 */
96 readonly requestModels?: {
97 [param: string]: IModel;
98 };
99 /**
100 * The ID of the associated request validator.
101 * Only one of `requestValidator` or `requestValidatorOptions` must be specified.
102 * Works together with `requestModels` or `requestParameters` to validate
103 * the request before it reaches integration like Lambda Proxy Integration.
104 * @default - No default validator
105 */
106 readonly requestValidator?: IRequestValidator;
107 /**
108 * A list of authorization scopes configured on the method. The scopes are used with
109 * a COGNITO_USER_POOLS authorizer to authorize the method invocation.
110 * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes
111 * @default - no authorization scopes
112 */
113 readonly authorizationScopes?: string[];
114 /**
115 * Request validator options to create new validator
116 * Only one of `requestValidator` or `requestValidatorOptions` must be specified.
117 * Works together with `requestModels` or `requestParameters` to validate
118 * the request before it reaches integration like Lambda Proxy Integration.
119 * @default - No default validator
120 */
121 readonly requestValidatorOptions?: RequestValidatorOptions;
122}
123export interface MethodProps {
124 /**
125 * The resource this method is associated with. For root resource methods,
126 * specify the `RestApi` object.
127 */
128 readonly resource: IResource;
129 /**
130 * The HTTP method ("GET", "POST", "PUT", ...) that clients use to call this method.
131 */
132 readonly httpMethod: string;
133 /**
134 * The backend system that the method calls when it receives a request.
135 *
136 * @default - a new `MockIntegration`.
137 */
138 readonly integration?: Integration;
139 /**
140 * Method options.
141 *
142 * @default - No options.
143 */
144 readonly options?: MethodOptions;
145}
146export declare class Method extends Resource {
147 /** @attribute */
148 readonly methodId: string;
149 readonly httpMethod: string;
150 readonly resource: IResource;
151 /**
152 * The API Gateway RestApi associated with this method.
153 */
154 readonly api: IRestApi;
155 private methodResponses;
156 constructor(scope: Construct, id: string, props: MethodProps);
157 /**
158 * The RestApi associated with this Method
159 * @deprecated - Throws an error if this Resource is not associated with an instance of `RestApi`. Use `api` instead.
160 */
161 get restApi(): RestApi;
162 /**
163 * Returns an execute-api ARN for this method:
164 *
165 * arn:aws:execute-api:{region}:{account}:{restApiId}/{stage}/{method}/{path}
166 *
167 * NOTE: {stage} will refer to the `restApi.deploymentStage`, which will
168 * automatically set if auto-deploy is enabled, or can be explicitly assigned.
169 * When not configured, {stage} will be set to '*', as a shorthand for 'all stages'.
170 *
171 * @attribute
172 */
173 get methodArn(): string;
174 /**
175 * Returns an execute-api ARN for this method's "test-invoke-stage" stage.
176 * This stage is used by the AWS Console UI when testing the method.
177 */
178 get testMethodArn(): string;
179 /**
180 * Add a method response to this method
181 */
182 addMethodResponse(methodResponse: MethodResponse): void;
183 private renderIntegration;
184 private renderMethodResponses;
185 private renderRequestModels;
186 private requestValidatorId;
187}
188export declare enum AuthorizationType {
189 /**
190 * Open access.
191 */
192 NONE = "NONE",
193 /**
194 * Use AWS IAM permissions.
195 */
196 IAM = "AWS_IAM",
197 /**
198 * Use a custom authorizer.
199 */
200 CUSTOM = "CUSTOM",
201 /**
202 * Use an AWS Cognito user pool.
203 */
204 COGNITO = "COGNITO_USER_POOLS"
205}