더 이상 사용되지 않는(Deprecated) 런타임을 사용하는 Lambda 함수에 대한 데이터 검색
더 이상 사용되지 않는(Deprecated) 런타임을 사용하는 Lambda 함수에 대한 데이터 검색
Lambda 런타임이 폐기(파지)에 가까워지면 Lambda가 이메일로 알리고 Health Dashboard와 Trusted Advisor에서 알림을 제공해요. 이 이메일과 알림에는 해당 런타임을 사용하는 함수의 $LATEST 버전이 나열돼요. 특정 런타임을 사용하는 모든 함수 버전을 나열하려면 AWS Command Line Interface(AWS CLI) 또는 AWS SDK 중 하나를 사용할 수 있어요.
폐기될 런타임을 사용하는 함수가 많다면 AWS CLI나 AWS SDK를 사용해서 가장 자주 호출되는 함수를 우선적으로 업데이트하는 데 도움을 줄 수도 있어요.
AWS CLI와 AWS SDK를 사용해서 특정 런타임을 사용하는 함수에 대한 데이터를 수집하는 방법은 다음 섹션을 참고하세요.
본문
특정 런타임을 사용하는 함수 버전 나열
AWS CLI를 사용해서 특정 런타임을 사용하는 모든 함수 버전을 나열하려면 다음 명령을 실행해요. RUNTIME_IDENTIFIER를 폐기되는 런타임의 이름으로 바꾸고 자신의 AWS 리전을 선택하세요. $LATEST 함수 버전만 나열하려면 명령에서 --function-version ALL을 생략해요.
aws lambda list-functions --function-version ALL --region {{us-east-1}} --output text --query "Functions[?Runtime=='{{RUNTIME_IDENTIFIER}}'].FunctionArn"
팁(Tip)
예시 명령은 특정 AWS 계정의 us-east-1 리전에서 함수를 나열해요. 계정에 함수가 있는 각 리전과 각 AWS 계정에 대해 이 명령을 반복해야 해요.
AWS SDK 중 하나를 사용해서 특정 런타임을 사용하는 함수를 나열할 수도 있어요. 다음 예시 코드는 JavaScript용 V3 AWS SDK와 Python용 AWS SDK(Boto3)를 사용해서 특정 런타임을 사용하는 함수의 함수 ARN 목록을 반환해요. 예시 코드는 나열된 각 함수의 CloudWatch 로그 그룹도 반환해요. 이 로그 그룹을 사용해서 함수의 마지막 호출 날짜를 찾을 수 있어요. 자세한 내용은 가장 자주 그리고 가장 최근에 호출된 함수 식별 섹션을 참고하세요.
Node.js
특정 런타임을 사용하는 함수를 나열하는 예시 JavaScript 코드
import { LambdaClient, ListFunctionsCommand } from "@aws-sdk/client-lambda";
const lambdaClient = new LambdaClient();
const command = new ListFunctionsCommand({
FunctionVersion: "ALL",
MaxItems: 50
});
const response = await lambdaClient.send(command);
for (const f of response.Functions){
if (f.Runtime == '{{<your_runtime>}}'){ // Use the runtime id, e.g. 'nodejs24.x' or 'python3.14'
console.log(f.FunctionArn);
// get the CloudWatch log group of the function to
// use later for finding the last invocation date
console.log(f.LoggingConfig.LogGroup);
}
}
// If your account has more functions than the specified
// MaxItems, use the returned pagination token in the
// next request with the 'Marker' parameter
if ('NextMarker' in response){
let paginationToken = response.NextMarker;
}
Python
특정 런타임을 사용하는 함수를 나열하는 예시 Python 코드
import boto3
from botocore.exceptions import ClientError
def list_lambda_functions(target_runtime):
lambda_client = boto3.client('lambda')
response = lambda_client.list_functions(
FunctionVersion='ALL',
MaxItems=50
)
if not response['Functions']:
print("No Lambda functions found")
else:
for function in response['Functions']:
if function['PackageType']=='Zip' and function['Runtime'] == target_runtime:
print(function['FunctionArn'])
# Print the CloudWatch log group of the function
# to use later for finding last invocation date
print(function['LoggingConfig']['LogGroup'])
if 'NextMarker' in response:
pagination_token = response['NextMarker']
if __name__ == "__main__":
# Replace python3.12 with the appropriate runtime ID for your Lambda functions
list_lambda_functions('{{python3.12}}')
ListFunctions 작업을 사용해 함수를 나열하는 AWS SDK 사용 방법에 대해 자세히 알아보려면 선호하는 프로그래밍 언어의 SDK 문서를 참고하세요.
AWS Config Advanced queries 기능을 사용해서 영향을 받는 런타임을 사용하는 모든 함수를 나열할 수도 있어요. 이 쿼리는 함수 $LATEST 버전만 반환하지만, 쿼리를 집계해서 단일 명령으로 모든 리전과 여러 AWS 계정의 함수를 나열할 수 있어요. 자세한 내용은 AWS Config 개발자 안내서의 AWS Auto Scaling 리소스의 현재 구성 상태 쿼리를 참고하세요.
가장 자주 그리고 가장 최근에 호출된 함수 식별
AWS 계정에 폐기될 런타임을 사용하는 함수가 있다면 자주 호출되는 함수나 최근에 호출된 함수를 우선적으로 업데이트하고 싶을 수 있어요.
함수가 몇 개뿐이라면 CloudWatch Logs 콘솔에서 함수의 로그 스트림을 보면서 이 정보를 수집할 수 있어요. 자세한 내용은 CloudWatch Logs로 전송된 로그 데이터 보기를 참고하세요.
최근 함수 호출 수를 보려면 Lambda 콘솔에 표시된 CloudWatch 메트릭 정보를 사용할 수도 있어요. 이 정보를 보려면 다음을 수행해요.
-
Lambda 콘솔의 Functions 페이지를 열어요.
-
호출 통계를 볼 함수를 선택해요.
-
Monitor 탭을 선택해요.
-
날짜 범위 선택기를 사용해서 통계를 볼 기간을 설정해요. 최근 호출은 Invocations 창에 표시돼요.
함수 수가 많은 계정의 경우 AWS CLI 또는 AWS SDK 중 하나를 사용해서 DescribeLogStreams와 GetMetricStatistics API 작업으로 이 데이터를 프로그래밍 방식으로 수집하는 것이 더 효율적일 수 있어요.
다음 예시는 JavaScript용 V3 AWS SDK와 Python용 AWS SDK(Boto3)를 사용해 특정 함수의 마지막 호출 날짜를 식별하고 지난 14일 동안의 특정 함수 호출 수를 결정하는 코드 조각을 제공해요.
Node.js
함수의 마지막 호출 시간을 찾는 예시 JavaScript 코드
import { CloudWatchLogsClient, DescribeLogStreamsCommand } from "@aws-sdk/client-cloudwatch-logs";
const cloudWatchLogsClient = new CloudWatchLogsClient();
const command = new DescribeLogStreamsCommand({
logGroupName: '{{<your_log_group_name>}}',
orderBy: 'LastEventTime',
descending: true,
limit: 1
});
try {
const response = await cloudWatchLogsClient.send(command);
const lastEventTimestamp = response.logStreams.length > 0 ?
response.logStreams[0].lastEventTimestamp : null;
// Convert the UNIX timestamp to a human-readable format for display
const date = new Date(lastEventTimestamp).toLocaleDateString();
const time = new Date(lastEventTimestamp).toLocaleTimeString();
console.log(`${date} ${time}`);
} catch (e){
console.error('Log group not found.')
}
Python
함수의 마지막 호출 시간을 찾는 예시 Python 코드
import boto3
from datetime import datetime
cloudwatch_logs_client = boto3.client('logs')
response = cloudwatch_logs_client.describe_log_streams(
logGroupName='{{<your_log_group_name>}}',
orderBy='LastEventTime',
descending=True,
limit=1
)
try:
if len(response['logStreams']) > 0:
last_event_timestamp = response['logStreams'][0]['lastEventTimestamp']
print(datetime.fromtimestamp(last_event_timestamp/1000)) # Convert timestamp from ms to seconds
else:
last_event_timestamp = None
except:
print('Log group not found')
팁(Tip) ListFunctions API 작업을 사용해서 함수의 로그 그룹 이름을 찾을 수 있어요. 이를 수행하는 방법의 예시는 특정 런타임을 사용하는 함수 버전 나열의 코드를 참고하세요.
Node.js
지난 14일 동안의 호출 수를 찾는 예시 JavaScript 코드
import { CloudWatchClient, GetMetricStatisticsCommand } from "@aws-sdk/client-cloudwatch";
const cloudWatchClient = new CloudWatchClient();
const command = new GetMetricStatisticsCommand({
Namespace: 'AWS/Lambda',
MetricName: 'Invocations',
StartTime: new Date(Date.now()-86400*1000*14), // 14 days ago
EndTime: new Date(Date.now()),
Period: 86400 * 14, // 14 days.
Statistics: ['Sum'],
Dimensions: [{
Name: 'FunctionName',
Value: '{{<your_function_name>}}'
}]
});
const response = await cloudWatchClient.send(command);
const invokesInLast14Days = response.Datapoints.length > 0 ?
response.Datapoints[0].Sum : 0;
console.log('Number of invocations: ' + invokesInLast14Days);
Python
지난 14일 동안의 호출 수를 찾는 예시 Python 코드
import boto3
from datetime import datetime, timedelta
cloudwatch_client = boto3.client('cloudwatch')
response = cloudwatch_client.get_metric_statistics(
Namespace='AWS/Lambda',
MetricName='Invocations',
Dimensions=[
{
'Name': 'FunctionName',
'Value': '{{<your_function_name>}}'
},
],
StartTime=datetime.now() - timedelta(days=14),
EndTime=datetime.now(),
Period=86400 * 14, # 14 days
Statistics=[
'Sum'
]
)
if len(response['Datapoints']) > 0:
invokes_in_last_14_days = int(response['Datapoints'][0]['Sum'])
else:
invokes_in_last_14_days = 0
print(f'Number of invocations: {invokes_in_last_14_days}')
더 알아보기 (Learn more)
Lambda 런타임 폐기에 대한 자세한 내용은 Lambda 런타임을 참고하세요.