Coder Social home page Coder Social logo

Comments (6)

mlctrez avatar mlctrez commented on June 15, 2024 6

@yosriady Yes that is possible. . A remote lambda running on AWS, no.

(edited) The following is an example of invoking a running go binary via RPC. You could for example use this to pprof / benchmark / test your binary before deployment...

The invoke method signature is defined at:

func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.InvokeResponse) error {

  • Server
package main

import (
	"os"

	"github.com/aws/aws-lambda-go/lambda"
)

func hello() (string, error) {
	return "Hello λ!", nil
}

func main() {

	// the _LAMBDA_SERVER_PORT environment would normally be provided externally
	os.Setenv("_LAMBDA_SERVER_PORT", "9988")

	lambda.Start(hello)

}

  • Client
package main

import (
	"fmt"
	"log"
	"net/rpc"

	"github.com/aws/aws-lambda-go/lambda/messages"
)

func main() {
	c, err := rpc.Dial("tcp", "127.0.0.1:9988")
	if err != nil {
		log.Fatalln(err)
	}

	var result messages.InvokeResponse
	request := &messages.InvokeRequest{}
	err = c.Call("Function.Invoke", request, &result)

	if err != nil {
		log.Fatal(err)
	}
	if result.Error != nil {
		log.Fatal(result.Error.Message)
	}

	fmt.Println("Function.Invoke =", string(result.Payload))

}

from aws-lambda-go.

bmoffatt avatar bmoffatt commented on June 15, 2024

@yosriady I'm guessing you mean invoking the uploaded Lambda function?

You are not limited to using API Gateway to Invoke your Lambda Function. You may also the AWS SDK for Go (or any language) to invoke your Lambda Function directly. https://github.com/aws/aws-sdk-go https://docs.aws.amazon.com/sdk-for-go/api/service/lambda/#Lambda.Invoke

from aws-lambda-go.

yosriady avatar yosriady commented on June 15, 2024

@mlctrez
How would rpc.Dial("tcp", "127.0.0.1:9988") work? Wouldn't you need to connect to the IP of the Lambda function?

from aws-lambda-go.

yosriady avatar yosriady commented on June 15, 2024

@bmoffatt

Yes, I'd like to invoke my Lambda function via both HTTP and RPC if possible.

I'm aware that we can invoke it using the AWS Lambda SDK.

from aws-lambda-go.

mlctrez avatar mlctrez commented on June 15, 2024

@yosriady
I read your question as wanting to test a go lambda binary locally. That was an incorrect assumption on my part.

For a Lambda running on AWS, the RPC IP and Port are not accessible outside of the AWS Lambda infrastructure.

from aws-lambda-go.

bmoffatt avatar bmoffatt commented on June 15, 2024

To go with @mlctrez comments:

From https://aws.amazon.com/lambda/faqs/

Q: What restrictions apply to AWS Lambda function code?

Lambda attempts to impose as few restrictions as possible on normal language and operating system activities, but there are a few activities that are disabled: Inbound network connections are blocked by AWS Lambda, and for outbound connections only TCP/IP sockets are supported, and ptrace (debugging) system calls are blocked. TCP port 25 traffic is also blocked as an anti-spam measure.

from aws-lambda-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.