AWS SDK 또는 CLI로 `GetFunction` 사용하기
AWS SDK 또는 CLI로 GetFunction 사용하기
다음 코드 예시는 GetFunction을 사용하는 방법을 보여줘요.
액션 예시는 더 큰 프로그램에서 발췌한 코드 일부로, 상황에 맞춰 실행해야 해요. 다음 코드 예시에서 이 액션을 실제로 확인할 수 있어요:
본문
.NET
SDK for .NET GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
/// <summary>
/// Gets information about a Lambda function.
/// </summary>
/// <param name="functionName">The name of the Lambda function for
/// which to retrieve information.</param>
/// <returns>Async Task.</returns>
public async Task<FunctionConfiguration> GetFunctionAsync(string functionName)
{
var functionRequest = new GetFunctionRequest
{
FunctionName = functionName,
};
var response = await _lambdaService.GetFunctionAsync(functionRequest);
return response.Configuration;
}
- API 세부 정보는 AWS SDK for .NET API Reference의 GetFunction을 참고하세요.
C++
SDK for C++ GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region in which the bucket was created (overrides config file).
// clientConfig.region = "us-east-1";
Aws::Lambda::LambdaClient client(clientConfig);
Aws::Lambda::Model::GetFunctionRequest request;
request.SetFunctionName(functionName);
Aws::Lambda::Model::GetFunctionOutcome outcome = client.GetFunction(request);
if (outcome.IsSuccess()) {
std::cout << "Function retrieve.\n" <<
outcome.GetResult().GetConfiguration().Jsonize().View().WriteReadable()
<< std::endl;
}
else {
std::cerr << "Error with Lambda::GetFunction. "
<< outcome.GetError().GetMessage()
<< std::endl;
}
- API 세부 정보는 AWS SDK for C++ API Reference의 GetFunction을 참고하세요.
CLI
AWS CLI
함수에 대한 정보 검색하기
다음 get-function 예시는 my-function 함수에 대한 정보를 표시해요.
aws lambda get-function \
--function-name {{my-function}}
출력:
{
"Concurrency": {
"ReservedConcurrentExecutions": 100
},
"Code": {
"RepositoryType": "S3",
"Location": "https://awslambda-us-west-2-tasks.s3.us-west-2.amazonaws.com/snapshots/123456789012/my-function..."
},
"Configuration": {
"TracingConfig": {
"Mode": "PassThrough"
},
"Version": "$LATEST",
"CodeSha256": "5tT2qgzYUHoqwR616pZ2dpkn/0J1FrzJmlKidWaaCgk=",
"FunctionName": "my-function",
"VpcConfig": {
"SubnetIds": [],
"VpcId": "",
"SecurityGroupIds": []
},
"MemorySize": 128,
"RevisionId": "28f0fb31-5c5c-43d3-8955-03e76c5c1075",
"CodeSize": 304,
"FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
"Handler": "index.handler",
"Role": "arn:aws:iam::123456789012:role/service-role/helloWorldPython-role-uy3l9qyq",
"Timeout": 3,
"LastModified": "2025-09-24T18:20:35.054+0000",
"Runtime": "nodejs22.x",
"Description": ""
}
}
자세한 내용은 AWS Lambda 개발자 안내서의 Lambda 함수 메모리 구성을 참고하세요.
- API 세부 정보는 AWS CLI 명령 참조의 GetFunction을 참고하세요.
Go
SDK for Go V2 GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
import (
"bytes"
"context"
"encoding/json"
"errors"
"log"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lambda"
"github.com/aws/aws-sdk-go-v2/service/lambda/types"
)
// FunctionWrapper encapsulates function actions used in the examples.
// It contains an AWS Lambda service client that is used to perform user actions.
type FunctionWrapper struct {
LambdaClient *lambda.Client
}
// GetFunction gets data about the Lambda function specified by functionName.
func (wrapper FunctionWrapper) GetFunction(ctx context.Context, functionName string) types.State {
var state types.State
funcOutput, err := wrapper.LambdaClient.GetFunction(ctx, &lambda.GetFunctionInput{
FunctionName: aws.String(functionName),
})
if err != nil {
log.Panicf("Couldn't get function %v. Here's why: %v\n", functionName, err)
} else {
state = funcOutput.Configuration.State
}
return state
}
- API 세부 정보는 AWS SDK for Go API Reference의 GetFunction을 참고하세요.
Java
SDK for Java 2.x GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
/**
* Retrieves information about an AWS Lambda function.
*
* @param awsLambda an instance of the {@link LambdaClient} class, which is used to interact with the AWS Lambda service
* @param functionName the name of the AWS Lambda function to retrieve information about
*/
public static void getFunction(LambdaClient awsLambda, String functionName) {
try {
GetFunctionRequest functionRequest = GetFunctionRequest.builder()
.functionName(functionName)
.build();
GetFunctionResponse response = awsLambda.getFunction(functionRequest);
System.out.println("The runtime of this Lambda function is " + response.configuration().runtime());
} catch (LambdaException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
- API 세부 정보는 AWS SDK for Java 2.x API Reference의 GetFunction을 참고하세요.
JavaScript
SDK for JavaScript (v3) GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
const getFunction = (funcName) => {
const client = new LambdaClient({});
const command = new GetFunctionCommand({ FunctionName: funcName });
return client.send(command);
};
- API 세부 정보는 AWS SDK for JavaScript API Reference의 GetFunction을 참고하세요.
PHP
SDK for PHP GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
public function getFunction($functionName)
{
return $this->lambdaClient->getFunction([
'FunctionName' => $functionName,
]);
}
- API 세부 정보는 AWS SDK for PHP API Reference의 GetFunction을 참고하세요.
Python
SDK for Python (Boto3) GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
class LambdaWrapper:
def __init__(self, lambda_client, iam_resource):
self.lambda_client = lambda_client
self.iam_resource = iam_resource
def get_function(self, function_name):
"""
Gets data about a Lambda function.
:param function_name: The name of the function.
:return: The function data.
"""
response = None
try:
response = self.lambda_client.get_function(FunctionName=function_name)
except ClientError as err:
if err.response["Error"]["Code"] == "ResourceNotFoundException":
logger.info("Function %s does not exist.", function_name)
else:
logger.error(
"Couldn't get function %s. Here's why: %s: %s",
function_name,
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
return response
- API 세부 정보는 AWS SDK for Python (Boto3) API Reference의 GetFunction을 참고하세요.
Ruby
SDK for Ruby GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
class LambdaWrapper
attr_accessor :lambda_client, :cloudwatch_client, :iam_client
def initialize
@lambda_client = Aws::Lambda::Client.new
@cloudwatch_client = Aws::CloudWatchLogs::Client.new(region: 'us-east-1')
@iam_client = Aws::IAM::Client.new(region: 'us-east-1')
@logger = Logger.new($stdout)
@logger.level = Logger::WARN
end
# Gets data about a Lambda function.
#
# @param function_name: The name of the function.
# @return response: The function data, or nil if no such function exists.
def get_function(function_name)
@lambda_client.get_function(
{
function_name: function_name
}
)
rescue Aws::Lambda::Errors::ResourceNotFoundException => e
@logger.debug("Could not find function: #{function_name}:\n #{e.message}")
nil
end
- API 세부 정보는 AWS SDK for Ruby API Reference의 GetFunction을 참고하세요.
Rust
SDK for Rust GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
/** Get the Lambda function with this Manager's name. */
pub async fn get_function(&self) -> Result<GetFunctionOutput, anyhow::Error> {
info!("Getting lambda function");
self.lambda_client
.get_function()
.function_name(self.lambda_name.clone())
.send()
.await
.map_err(anyhow::Error::from)
}
- API 세부 정보는 AWS SDK for Rust API reference의 GetFunction을 참고하세요.
SAP ABAP
SDK for SAP ABAP GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
TRY.
oo_result = lo_lmd->getfunction( iv_functionname = iv_function_name ). " oo_result is returned for testing purposes. "
MESSAGE 'Lambda function information retrieved.' TYPE 'I'.
CATCH /aws1/cx_lmdinvparamvalueex.
MESSAGE 'The request contains a non-valid parameter.' TYPE 'E'.
CATCH /aws1/cx_lmdserviceexception.
MESSAGE 'An internal problem was encountered by the AWS Lambda service.' TYPE 'E'.
CATCH /aws1/cx_lmdtoomanyrequestsex.
MESSAGE 'The maximum request throughput was reached.' TYPE 'E'.
ENDTRY.
- API 세부 정보는 AWS SDK for SAP ABAP API reference의 GetFunction을 참고하세요.
Swift
SDK for Swift GitHub에 더 많은 내용이 있어요. 전체 예시와 설정·실행 방법은 AWS Code Examples Repository에서 확인하세요.
import AWSClientRuntime
import AWSLambda
import Foundation
/// Detect whether or not the AWS Lambda function with the specified name
/// exists, by requesting its function information.
///
/// - Parameters:
/// - lambdaClient: The `LambdaClient` to use.
/// - name: The name of the AWS Lambda function to find.
///
/// - Returns: `true` if the Lambda function exists. Otherwise `false`.
func doesLambdaFunctionExist(lambdaClient: LambdaClient, name: String) async -> Bool {
do {
_ = try await lambdaClient.getFunction(
input: GetFunctionInput(functionName: name)
)
} catch {
return false
}
return true
}
- API 세부 정보는 AWS SDK for Swift API reference의 GetFunction을 참고하세요.
더 알아보기 (Learn more)
AWS SDK 개발자 안내서와 코드 예시의 전체 목록은 AWS SDK와 함께 Lambda 사용을 참고하세요. 이 주제에는 시작하기와 이전 SDK 버전에 대한 정보도 포함돼 있어요.