Hello Lambda 예제로 시작하기

Hello Lambda 예제로 시작하기 (Hello Lambda)

Lambda를 처음 접할 때 가장 간단한 시작 방법 중 하나가 바로 기존 계정에 있는 Lambda 함수 목록을 불러와 보는 거예요. 이 예제 페이지는 여러 AWS SDK에서 "Hello Lambda" 격으로 계정의 Lambda 함수를 나열(list)하는 코드를 보여줘요.

출처: AWS Lambda 개발자 안내서

본문

다음 코드 예제는 Lambda 사용을 시작하는 방법을 보여줘요. 지원 언어는 .NET, C++, Go, Java, JavaScript, Kotlin, PHP, Python, Ruby, Rust, Swift 등으로 각 예제는 계정에 존재하는 Lambda 함수를 나열해요.

참고
GitHub에 더 많은 내용이 있어요. 전체 예제와 설치·실행 방법은 AWS Code Examples Repository 에서 확인할 수 있어요.

.NET (SDK for .NET)

namespace LambdaActions;

using Amazon.Lambda;

public class HelloLambda
{
    static async Task Main(string[] args)
    {
        var lambdaClient = new AmazonLambdaClient();

        Console.WriteLine("Hello AWS Lambda");
        Console.WriteLine("Let's get started with AWS Lambda by listing your existing Lambda functions:");

        var response = await lambdaClient.ListFunctionsAsync();
        response.Functions.ForEach(function =>
        {
            Console.WriteLine($"{function.FunctionName}\t{function.Description}");
        });
    }
}
  • API 세부 정보는 AWS SDK for .NET API Reference 의 ListFunctions 를 참고하세요.

C++ (SDK for C++)

C++ 예제는 빌드 설정 파일(CMakeLists.txt)과 소스 파일(hello_lambda.cpp)로 구성돼요. 다음은 소스 파일의 핵심 코드예요.

#include <aws/core/Aws.h>
#include <aws/lambda/LambdaClient.h>
#include <aws/lambda/model/ListFunctionsRequest.h>
#include <iostream>

int main(int argc, char **argv)
{
    Aws::SDKOptions options;
    Aws::InitAPI(options); // Should only be called once.
    int result = 0;
    {
        Aws::Client::ClientConfiguration clientConfig;
        Aws::Lambda::LambdaClient client(clientConfig);

        Aws::Lambda::Model::ListFunctionsRequest request;
        auto outcome = client.ListFunctions(request);
        if (outcome.IsSuccess())
        {
            for (auto const& f : outcome.GetResult().GetFunctions())
            {
                std::cout << f.GetFunctionName() << std::endl;
            }
        }
        else
        {
            std::cerr << "Failed with error: " << outcome.GetError().GetMessage() << std::endl;
        }
    }
    Aws::ShutdownAPI(options);
    return result;
}
  • API 세부 정보는 AWS SDK for C++ API Reference 의 ListFunctions 를 참고하세요.

그 외 언어 예제

Go, Java, JavaScript, Kotlin, PHP, Python, Ruby, Rust, Swift 용 예제도 같은 패턴으로 ListFunctions를 호출해요. 여러 언어의 전체 코드와 실행 방법은 AWS Code Examples Repository 의 Lambda 예제에서 확인할 수 있어요.

더 알아보기 (Learn more)