How to call Lambda function by iOS SDK?

2019-03-03 22:01发布

I have an iOS Shopping App and want to call a lambda Function for logging. But i dont want to call the lambda function by an API Gateway to save costs. Is there a possibility to send logs to Lambda by using the iOS SDK of Amazon?

1条回答
贼婆χ
2楼-- · 2019-03-03 22:17

You can invoke lambda functions directly using the AWS iOS SDK. Here is a code snippet

AWSLambda *lambda = [AWSLambda defaultLambda];
AWSLambdaInvocationRequest *invocationRequest = [AWSLambdaInvocationRequest new];
invocationRequest.functionName = @"functionname";
invocationRequest.invocationType = AWSLambdaInvocationTypeRequestResponse;
NSDictionary *parameters = ...

invocationRequest.payload = [NSJSONSerialization dataWithJSONObject:parameters
                                                            options:kNilOptions
                                                              error:nil];

[lambda invoke:invocationRequest] 

The integration test shown here https://github.com/aws-amplify/aws-sdk-ios/blob/335e4d82a641fdb9cdc84773bf115951e850b884/AWSLambdaTests/AWSLambdaTests.m#L110 demonstrates how you can invoke a lamdba function and validate the results.

查看更多
登录 后发表回答