Open blmayer opened 4 years ago
Were you able to setup sam local start-lamba
? This would allow you to call into lambda locally.
Yes I set that up, but same behaviour, the first lambda is called locally, but it calls the second lambda of the AWS cloud.
@blmayer can you post your template.yaml
please
Here's my template.yaml.
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
cloud
My cloud lambda services
Resources:
lambda1:
Type: AWS::Serverless::Function
Properties:
FunctionName: "lambda1"
Handler: lambda1
Runtime: go1.x
CodeUri: lambda1/
Events:
GatewayApiProxyGet:
Type: Api
Properties:
Path: /{proxy+}
Method: get
lambda2:
Type: AWS::Serverless::Function
Properties:
FunctionName: "lambda2"
Handler: lambda2
Runtime: go1.x
CodeUri: lambda2/
Anything?
@blmayer Hi. Did you find any workaround for this?
I'm wondering this same thing. It seems there should be an option to test all the invoked lambdas locally. Anything new on this?
I'm also working with similar problem. We have a setup were we have ApiGW with lambda-functions and then we have a proxy lambda in our private VPC to connect to private resources. Call through ApiGW goes to "public" lambda function which invokes the proxy lambda.
My problem is how to test this locally.
I've started sam local start-lambda
and i'm able to invoke my local proxy lambda from command line.
But when i start sam local start-api
and try to invoke the same proxy lambda from another lambda run by start-api i get connection error and it seems that the call is going to AWS Lambda and not to my local Lambda. I've tried to follow this document https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-lambda.html.
I get this error message:
{"message":"Inaccessible host:
127.0.0.1'. This service may not be available in the eu-west-1' region.","code":"UnknownEndpoint","region":"eu-west-1","hostname":"127.0.0.1","retryable":true,"originalError":{"message":"connect ECONNREFUSED 127.0.0.1:3001","errno":-111,"code":"NetworkingError","syscall":"connect","address":"127.0.0.1","port":3001,"region":"eu-west-1","hostname":"127.0.0.1","retryable":true,"time":"2021-06-08T13:09:26.027Z"},"time":"2021-06-08T13:09:26.027Z"}
In my ApiGW lambda i tried to initialize the Lambda service like this:
const Lambda = new AWS.Lambda({ endpoint: "http://127.0.0.1:3001", sslEnabled: false, maxRetries: 0 })
I am having the same issue, and news?
EDIT: I actually could solve it on linux by running:
$sam local start-lambda --host 172.17.0.1
and in my python file:
import boto3
client = boto3.client('lambda', endpoint_url='http://172.17.0.1:3001', use_ssl=False, verify=False)
client.invoke(FunctionName="TestFunction", InvocationType='RequestResponse')
The 172.17.0.1 ip comes from https://stackoverflow.com/questions/48546124/what-is-linux-equivalent-of-host-docker-internal/61001152
Unfortunately I still have not a deep understanding on how this solved my issue.
I have a CDK application where I have an API GW with a lambda function which internally invokes another lambda function. This is what I have: API GW -> Lambda1 -> Lambda2
When I try to start everything up locally. I get
"stack": "ResourceNotFoundException: Function not found: arn:aws:lambda:SOME_MORE_ARN_THING
Need help.
Description
First, invocations done by the go-lambda-sdk using the
lambda.invoke()
function go to deployed AWS lambda instead of the local ones created bysam local start-api
.Second, only lambdas that receives events are being actually mounted on the local container for testing, I think this is not the desired behaviour. I expected my local test environment call other lambdas that are also local.
Steps to reproduce
Create a template.yml with 2 lambdas: one receives the event from the api, the other is just defined on the file. In the code of the first lambda use the sdk to call the second lambda:
lambda1 code:
This is a Golang example, I haven't tried with other languages. The second lambda just needs to receive and return some JSON:
lambda2 code:
Then build and start the local API, the request from the first lambda never hits the second lambda.
Observed result
Addressing the mounting issue, this is what I get:
And this is when I put an API event on the two lambdas:
EDIT: I chaned the token text, the real name of my lambdas and the path of lambdas' code to not show the real one.
Expected result
I expect that the lambdas on my local environment invoke other lambdas in my environment instead of the deployed ones.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Thanks a lot for this yet great tool!