如何通过iOS SDK调用Lambda函数? [英] How to call Lambda function by iOS SDK?
问题描述
我有一个iOS购物应用程序,想调用lambda函数进行记录.但是我不想通过API网关调用lambda函数以节省成本.是否可以使用Amazon的iOS SDK将日志发送到Lambda?
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?
推荐答案
您可以直接使用AWS iOS SDK调用lambda函数.这是一个代码段
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]
此处显示的集成测试 https://github.com/aws-amplify/aws-sdk-ios/blob/335e4d82a641fdb9cdc84773bf115951e850b884/AWSLambdaTests/AWSLambdaTests.m#L110 演示了如何调用lamdba函数并验证结果.
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.
这篇关于如何通过iOS SDK调用Lambda函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!