example ejemplo deploy aws java amazon-web-services lambda aws-api-gateway

java - ejemplo - deploy jar to aws lambda



AWS Lambda obtiene valor nulo como cadena de consulta (1)

Si está utilizando la integración AWS_PROXY , API Gateway ignorará sus plantillas de asignación. API Gateway enviará los parámetros en este formato a su función Lambda.

{ "message": "Hello me!", "input": { "path": "/test/hello", "headers": { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Encoding": "gzip, deflate, lzma, sdch, br", "Accept-Language": "en-US,en;q=0.8", "CloudFront-Forwarded-Proto": "https", "CloudFront-Is-Desktop-Viewer": "true", "CloudFront-Is-Mobile-Viewer": "false", "CloudFront-Is-SmartTV-Viewer": "false", "CloudFront-Is-Tablet-Viewer": "false", "CloudFront-Viewer-Country": "US", "Host": "wt6mne2s9k.execute-api.us-west-2.amazonaws.com", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", "Via": "1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)", "X-Amz-Cf-Id": "nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==", "X-Forwarded-For": "192.168.100.1, 192.168.1.1", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, "pathParameters": {"proxy": "hello"}, "requestContext": { "accountId": "123456789012", "resourceId": "us4z18", "stage": "test", "requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9", "identity": { "cognitoIdentityPoolId": "", "accountId": "", "cognitoIdentityId": "", "caller": "", "apiKey": "", "sourceIp": "192.168.100.1", "cognitoAuthenticationType": "", "cognitoAuthenticationProvider": "", "userArn": "", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48", "user": "" }, "resourcePath": "/{proxy+}", "httpMethod": "GET", "apiId": "wt6mne2s9k" }, "resource": "/{proxy+}", "httpMethod": "GET", "queryStringParameters": {"name": "me"}, "stageVariables": {"stageVarName": "stageVarValue"} } }

AWS::ApiGateway::Method mi AWS::ApiGateway::Method como este

GetOrdersMethod: Type: "AWS::ApiGateway::Method" Properties: ApiKeyRequired: true AuthorizationType: "AWS_IAM" HttpMethod: "GET" RequestParameters: method.request.querystring.orderId: false ResourceId: Ref: "GetOrdersPathResource" RestApiId: Ref: "GetOrders" Integration: Type: "AWS_PROXY" IntegrationHttpMethod: "POST" RequestTemplates: application/json: !Join ["", ["{","/"orderId/": /"$input.params(''orderId'')/"","}"]] Uri: !Join ["", ["arn:aws:apigateway:", !Ref "AWS::Region", ":lambda:path/2015-03-31/functions/",!GetAtt GetProgramsLambdaFunction.Arn, "/invocations"]]

Mi controlador se define así

public class ProgramHandler implements RequestHandler<Request, String>{ private LambdaLogger logger; @Override public String handleRequest(Request request, Context context) { logger = context.getLogger(); logger.log("FROM LOGGER: ======= LAMBDA INVOKED ======"); logger.log("Input value: " +request.getOrderId()); System.out.println("======= LAMBDA INVOKED ======"); System.out.println("Input value: " +request.getMarketplaceId()); return "Lambda Invoked successfully"; } }

Y la Solicitud es un simple java pojo con orderId como solo campos que tienen GETTERS y SETTERS necesarios

Cuando probé API Gateway, vi que en mis registros lambda, el ID de la orden era nulo. Sin embargo, sí veo que se pasa como cadena de consulta en los registros ... aquí está

Tue Apr 25 21:57:31 UTC 2017 : Endpoint request body after transformations: {"resource":"/xxxx","path":"/xxxx","httpMethod":"GET","headers":null,"queryStringParameters":{"orderId":"32"},"pathParameters":null,"stageVariables":null,"requestContext":{"accountId":"xxxxxxx","resourceId":"xxxxx","stage":"test-invoke-stage", ... }

¿Por qué estoy obteniendo null orderId en mi handler ?