2017-07-26 9 views

Antwort

1

Die Reversion des Lambda kann nur über das AWS SDK erfolgen. Sie müssen die folgenden Schritte ausführen, um zum Implementierungs-URI des Lambda zu gelangen.

Schritte:

  • die API-Ressourcen für Ihre API für diese Ressource
  • Extrahieren Sie die Lambda ARN aus dem Ziel-URI

In-Code

  • Holen Sie sich das Integrations holen würde dies sehe so aus.

    var aws = require('aws-sdk'); 
    var apigateway = new aws.APIGateway(); 
    exports.handler = (event, context, callback) => { 
        //sample methodArn: 'arn:aws:execute-api:eu-west-1:1234567890:p2llm1cs/prod/GET/blah/gerfea' 
        var section = event.methodArn.substring(event.methodArn.lastIndexOf(':') + 1); 
        var restId = section.split('\/')[0]; 
        var method = section.split('\/')[2]; 
        var path = section.substring(section.indexOf(method) + method.length); 
    
        //getting the resources for the given API 
        var params = { 
        restApiId: restId, 
        }; 
        apigateway.getResources(params, function(err, data) { 
        //iterate through all attached resources 
        for (var idx = 0; idx < data.items.length; idx++) { 
         var item = data.items[idx]; 
         if (item.path == path) { 
         //get the integration for the matching resource. 
         var params = { 
          httpMethod: method, 
          resourceId: item.id, 
          restApiId: restId 
         }; 
         apigateway.getIntegration(params, function(err, data) { 
          //sample data.uri arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:1234567890:function:echo/invocations 
          console.log(data.uri); 
          callback(null, 'Hello from Lambda'); 
         }); 
         } 
        } 
        }); 
    }; 
    
  • Verwandte Themen