github.com/Foodji/aws-lambda-go@v1.20.2/events/apigw.go (about) 1 // Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 3 package events 4 5 // APIGatewayProxyRequest contains data coming from the API Gateway proxy 6 type APIGatewayProxyRequest struct { 7 Resource string `json:"resource"` // The resource path defined in API Gateway 8 Path string `json:"path"` // The url path for the caller 9 HTTPMethod string `json:"httpMethod"` 10 Headers map[string]string `json:"headers"` 11 MultiValueHeaders map[string][]string `json:"multiValueHeaders"` 12 QueryStringParameters map[string]string `json:"queryStringParameters"` 13 MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"` 14 PathParameters map[string]string `json:"pathParameters"` 15 StageVariables map[string]string `json:"stageVariables"` 16 RequestContext APIGatewayProxyRequestContext `json:"requestContext"` 17 Body string `json:"body"` 18 IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` 19 } 20 21 // APIGatewayProxyResponse configures the response to be returned by API Gateway for the request 22 type APIGatewayProxyResponse struct { 23 StatusCode int `json:"statusCode"` 24 Headers map[string]string `json:"headers"` 25 MultiValueHeaders map[string][]string `json:"multiValueHeaders"` 26 Body string `json:"body"` 27 IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` 28 } 29 30 // APIGatewayProxyRequestContext contains the information to identify the AWS account and resources invoking the 31 // Lambda function. It also includes Cognito identity information for the caller. 32 type APIGatewayProxyRequestContext struct { 33 AccountID string `json:"accountId"` 34 ResourceID string `json:"resourceId"` 35 OperationName string `json:"operationName,omitempty"` 36 Stage string `json:"stage"` 37 DomainName string `json:"domainName"` 38 DomainPrefix string `json:"domainPrefix"` 39 RequestID string `json:"requestId"` 40 Protocol string `json:"protocol"` 41 Identity APIGatewayRequestIdentity `json:"identity"` 42 ResourcePath string `json:"resourcePath"` 43 Authorizer map[string]interface{} `json:"authorizer"` 44 HTTPMethod string `json:"httpMethod"` 45 RequestTime string `json:"requestTime"` 46 RequestTimeEpoch int64 `json:"requestTimeEpoch"` 47 APIID string `json:"apiId"` // The API Gateway rest API Id 48 } 49 50 // APIGatewayV2HTTPRequest contains data coming from the new HTTP API Gateway 51 type APIGatewayV2HTTPRequest struct { 52 Version string `json:"version"` 53 RouteKey string `json:"routeKey"` 54 RawPath string `json:"rawPath"` 55 RawQueryString string `json:"rawQueryString"` 56 Cookies []string `json:"cookies,omitempty"` 57 Headers map[string]string `json:"headers"` 58 QueryStringParameters map[string]string `json:"queryStringParameters,omitempty"` 59 PathParameters map[string]string `json:"pathParameters,omitempty"` 60 RequestContext APIGatewayV2HTTPRequestContext `json:"requestContext"` 61 StageVariables map[string]string `json:"stageVariables,omitempty"` 62 Body string `json:"body,omitempty"` 63 IsBase64Encoded bool `json:"isBase64Encoded"` 64 } 65 66 // APIGatewayV2HTTPRequestContext contains the information to identify the AWS account and resources invoking the Lambda function. 67 type APIGatewayV2HTTPRequestContext struct { 68 RouteKey string `json:"routeKey"` 69 AccountID string `json:"accountId"` 70 Stage string `json:"stage"` 71 RequestID string `json:"requestId"` 72 Authorizer *APIGatewayV2HTTPRequestContextAuthorizerDescription `json:"authorizer,omitempty"` 73 APIID string `json:"apiId"` // The API Gateway HTTP API Id 74 DomainName string `json:"domainName"` 75 DomainPrefix string `json:"domainPrefix"` 76 Time string `json:"time"` 77 TimeEpoch int64 `json:"timeEpoch"` 78 HTTP APIGatewayV2HTTPRequestContextHTTPDescription `json:"http"` 79 } 80 81 // APIGatewayV2HTTPRequestContextAuthorizerDescription contains authorizer information for the request context. 82 type APIGatewayV2HTTPRequestContextAuthorizerDescription struct { 83 JWT *APIGatewayV2HTTPRequestContextAuthorizerJWTDescription `json:"jwt,omitempty"` 84 Lambda map[string]interface{} `json:"lambda,omitempty"` 85 IAM *APIGatewayV2HTTPRequestContextAuthorizerIAMDescription `json:"iam,omitempty"` 86 } 87 88 // APIGatewayV2HTTPRequestContextAuthorizerJWTDescription contains JWT authorizer information for the request context. 89 type APIGatewayV2HTTPRequestContextAuthorizerJWTDescription struct { 90 Claims map[string]string `json:"claims"` 91 Scopes []string `json:"scopes,omitempty"` 92 } 93 94 // APIGatewayV2HTTPRequestContextAuthorizerIAMDescription contains IAM information for the request context. 95 type APIGatewayV2HTTPRequestContextAuthorizerIAMDescription struct { 96 AccessKey string `json:"accessKey"` 97 AccountID string `json:"accountId"` 98 CallerID string `json:"callerId"` 99 CognitoIdentity APIGatewayV2HTTPRequestContextAuthorizerCognitoIdentity `json:"cognitoIdentity,omitempty"` 100 PrincipalOrgID string `json:"principalOrgId"` 101 UserARN string `json:"userArn"` 102 UserID string `json:"userId"` 103 } 104 105 // APIGatewayV2HTTPRequestContextAuthorizerCognitoIdentity contains Cognito identity information for the request context. 106 type APIGatewayV2HTTPRequestContextAuthorizerCognitoIdentity struct { 107 AMR []string `json:"amr"` 108 IdentityID string `json:"identityId"` 109 IdentityPoolID string `json:"identityPoolId"` 110 } 111 112 // APIGatewayV2HTTPRequestContextHTTPDescription contains HTTP information for the request context. 113 type APIGatewayV2HTTPRequestContextHTTPDescription struct { 114 Method string `json:"method"` 115 Path string `json:"path"` 116 Protocol string `json:"protocol"` 117 SourceIP string `json:"sourceIp"` 118 UserAgent string `json:"userAgent"` 119 } 120 121 // APIGatewayV2HTTPResponse configures the response to be returned by API Gateway V2 for the request 122 type APIGatewayV2HTTPResponse struct { 123 StatusCode int `json:"statusCode"` 124 Headers map[string]string `json:"headers"` 125 MultiValueHeaders map[string][]string `json:"multiValueHeaders"` 126 Body string `json:"body"` 127 IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` 128 Cookies []string `json:"cookies"` 129 } 130 131 // APIGatewayRequestIdentity contains identity information for the request caller. 132 type APIGatewayRequestIdentity struct { 133 CognitoIdentityPoolID string `json:"cognitoIdentityPoolId"` 134 AccountID string `json:"accountId"` 135 CognitoIdentityID string `json:"cognitoIdentityId"` 136 Caller string `json:"caller"` 137 APIKey string `json:"apiKey"` 138 APIKeyID string `json:"apiKeyId"` 139 AccessKey string `json:"accessKey"` 140 SourceIP string `json:"sourceIp"` 141 CognitoAuthenticationType string `json:"cognitoAuthenticationType"` 142 CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"` 143 UserArn string `json:"userArn"` 144 UserAgent string `json:"userAgent"` 145 User string `json:"user"` 146 } 147 148 // APIGatewayWebsocketProxyRequest contains data coming from the API Gateway proxy 149 type APIGatewayWebsocketProxyRequest struct { 150 Resource string `json:"resource"` // The resource path defined in API Gateway 151 Path string `json:"path"` // The url path for the caller 152 HTTPMethod string `json:"httpMethod"` 153 Headers map[string]string `json:"headers"` 154 MultiValueHeaders map[string][]string `json:"multiValueHeaders"` 155 QueryStringParameters map[string]string `json:"queryStringParameters"` 156 MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"` 157 PathParameters map[string]string `json:"pathParameters"` 158 StageVariables map[string]string `json:"stageVariables"` 159 RequestContext APIGatewayWebsocketProxyRequestContext `json:"requestContext"` 160 Body string `json:"body"` 161 IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` 162 } 163 164 // APIGatewayWebsocketProxyRequestContext contains the information to identify 165 // the AWS account and resources invoking the Lambda function. It also includes 166 // Cognito identity information for the caller. 167 type APIGatewayWebsocketProxyRequestContext struct { 168 AccountID string `json:"accountId"` 169 ResourceID string `json:"resourceId"` 170 Stage string `json:"stage"` 171 RequestID string `json:"requestId"` 172 Identity APIGatewayRequestIdentity `json:"identity"` 173 ResourcePath string `json:"resourcePath"` 174 Authorizer interface{} `json:"authorizer"` 175 HTTPMethod string `json:"httpMethod"` 176 APIID string `json:"apiId"` // The API Gateway rest API Id 177 ConnectedAt int64 `json:"connectedAt"` 178 ConnectionID string `json:"connectionId"` 179 DomainName string `json:"domainName"` 180 Error string `json:"error"` 181 EventType string `json:"eventType"` 182 ExtendedRequestID string `json:"extendedRequestId"` 183 IntegrationLatency string `json:"integrationLatency"` 184 MessageDirection string `json:"messageDirection"` 185 MessageID interface{} `json:"messageId"` 186 RequestTime string `json:"requestTime"` 187 RequestTimeEpoch int64 `json:"requestTimeEpoch"` 188 RouteKey string `json:"routeKey"` 189 Status string `json:"status"` 190 } 191 192 // APIGatewayCustomAuthorizerRequestTypeRequestIdentity contains identity information for the request caller. 193 type APIGatewayCustomAuthorizerRequestTypeRequestIdentity struct { 194 APIKey string `json:"apiKey"` 195 SourceIP string `json:"sourceIp"` 196 } 197 198 // APIGatewayCustomAuthorizerContext represents the expected format of an API Gateway custom authorizer response. 199 // Deprecated. Code should be updated to use the Authorizer map from APIGatewayRequestIdentity. Ex: Authorizer["principalId"] 200 type APIGatewayCustomAuthorizerContext struct { 201 PrincipalID *string `json:"principalId"` 202 StringKey *string `json:"stringKey,omitempty"` 203 NumKey *int `json:"numKey,omitempty"` 204 BoolKey *bool `json:"boolKey,omitempty"` 205 } 206 207 // APIGatewayCustomAuthorizerRequestTypeRequestContext represents the expected format of an API Gateway custom authorizer response. 208 type APIGatewayCustomAuthorizerRequestTypeRequestContext struct { 209 Path string `json:"path"` 210 AccountID string `json:"accountId"` 211 ResourceID string `json:"resourceId"` 212 Stage string `json:"stage"` 213 RequestID string `json:"requestId"` 214 Identity APIGatewayCustomAuthorizerRequestTypeRequestIdentity `json:"identity"` 215 ResourcePath string `json:"resourcePath"` 216 HTTPMethod string `json:"httpMethod"` 217 APIID string `json:"apiId"` 218 } 219 220 // APIGatewayCustomAuthorizerRequest contains data coming in to a custom API Gateway authorizer function. 221 type APIGatewayCustomAuthorizerRequest struct { 222 Type string `json:"type"` 223 AuthorizationToken string `json:"authorizationToken"` 224 MethodArn string `json:"methodArn"` 225 } 226 227 // APIGatewayCustomAuthorizerRequestTypeRequest contains data coming in to a custom API Gateway authorizer function. 228 type APIGatewayCustomAuthorizerRequestTypeRequest struct { 229 Type string `json:"type"` 230 MethodArn string `json:"methodArn"` 231 Resource string `json:"resource"` 232 Path string `json:"path"` 233 HTTPMethod string `json:"httpMethod"` 234 Headers map[string]string `json:"headers"` 235 MultiValueHeaders map[string][]string `json:"multiValueHeaders"` 236 QueryStringParameters map[string]string `json:"queryStringParameters"` 237 MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"` 238 PathParameters map[string]string `json:"pathParameters"` 239 StageVariables map[string]string `json:"stageVariables"` 240 RequestContext APIGatewayCustomAuthorizerRequestTypeRequestContext `json:"requestContext"` 241 } 242 243 // APIGatewayCustomAuthorizerResponse represents the expected format of an API Gateway authorization response. 244 type APIGatewayCustomAuthorizerResponse struct { 245 PrincipalID string `json:"principalId"` 246 PolicyDocument APIGatewayCustomAuthorizerPolicy `json:"policyDocument"` 247 Context map[string]interface{} `json:"context,omitempty"` 248 UsageIdentifierKey string `json:"usageIdentifierKey,omitempty"` 249 } 250 251 // APIGatewayCustomAuthorizerPolicy represents an IAM policy 252 type APIGatewayCustomAuthorizerPolicy struct { 253 Version string 254 Statement []IAMPolicyStatement 255 } 256 257 // IAMPolicyStatement represents one statement from IAM policy with action, effect and resource 258 type IAMPolicyStatement struct { 259 Action []string 260 Effect string 261 Resource []string 262 }