Reputation: 96454
The 2nd lambda works and inserts a record into dynamoDB when I test it alone.
I then have another lambda which is trying to call it but nothing seems to happen.
Cloudwatch logs show no issues and show puts statements after call.
But dynamodb table doesn't get any records inserted.
Both lambdas have full lambda acccess
2nd lambda that works on its own:
# lambda 'two'
require 'aws-sdk-lambda'
require 'aws-sdk-dynamodb'
require 'time'
require 'json'
def handler(event:, context:)
p "index2"
dynamodb = Aws::DynamoDB::Client.new(region: 'us-east-2')
item = {
"name": "#{Time.now.to_s[0..19]} #{event['Records'][0]['eventSource']} #{event['Records'][0]['eventName']}",
"eventTime": "#{Time.now.to_s[0..19]}",
"eventSource": "lambda",
"description": "from lambda event",
"eventID": "#{event['Records'][0]['eventID']}",
"eventName": "#{event['Records'][0]['eventName']}",
"eventSource":"#{event['Records'][0]['eventSource']}",
"awsRegion":"#{event['Records'][0]['awsRegion']}"
}
params = {
table_name: 'any_event',
item: item
}
begin
dynamodb.put_item(params)
puts 'Added item'
rescue Aws::DynamoDB::Errors::ServiceError => error
puts 'Unable to add item:'
puts error.message
end
end
First Lambda that is trying to call it:
require 'aws-sdk-lambda'
require 'time'
require 'json'
def lambda_handler(event:, context:)
client = Aws::Lambda::Client.new(region: 'us-east-2')
payload = '{"name": "thing"}'
the_payload = JSON.generate(payload)
resp = client.invoke({
function_name: 'LamdaLamdaDynamodb',
invocation_type: 'RequestResponse',
log_type: 'None',
payload: the_payload
})
end
Upvotes: 1
Views: 204
Reputation: 2355
lambda:InvokeFunction
action.invocationType=RequestResponse
(its the default type).AWSJavaScriptSDKinvoke_resp = LAMBDA_CLIENT.invoke(
FunctionName='second_lambda',
InvocationType='RequestResponse',
Payload=encoded_payload)
invocationType
are as follows RequestResponse (default)
, Event
and DryRun
.aws docs Depending upon your synchronous invocation or asynchronous invocation.Upvotes: 2
Reputation: 915
IMO: [3] is the easiest way to do this. You can also try setting the function_name parameter to the ARN of the Lambda function.
Upvotes: 1