Notice
Recent Posts
Recent Comments
Link
투케이2K
493. (javaScript) 자바스크립트 AWS Lambda 함수 목록 리스트 조회 수행 - ListFunctions 본문
JavaScript
493. (javaScript) 자바스크립트 AWS Lambda 함수 목록 리스트 조회 수행 - ListFunctions
투케이2K 2026. 2. 21. 19:23728x90
반응형
[개발 환경 설정]
개발 툴 : Edit++
개발 언어 : JavaScript

[소스 코드]
-----------------------------------------------------------------------------------------
[사전 설명 및 설정 사항]
-----------------------------------------------------------------------------------------
- 개발 환경 : Web
- 개발 기술 : JavaScript (자바스크립트) / AWS / Lambda / ListFunctions
- 사전) AWS Lambda 간단 설명 :
>> Aws Lambda 는 서버 리스 FaaS 솔루션으로, 함수의 인스턴스를 실행하여 이벤트를 처리할 수 있습니다.
>> Aws Lambda 는 이벤트에 응답하여 코드를 실행 하고 해당 코드에 필요한 컴퓨팅 리소스를 자동으로 관리합니다.
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[소스 코드]
-----------------------------------------------------------------------------------------
<!DOCTYPE HTML>
<html lang="ko">
<head>
<title>javaScriptTest</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 반응형 구조 만들기 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<!-- 내부 CSS 스타일 지정 -->
<style>
html, body {
width: 100%;
height: 100%;
margin : 0 auto;
padding : 0;
border : none;
background-color: #666;
}
</style>
<!-- [CDN 주소 설정] -->
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1416.0.min.js"></script>
<!-- [자바스크립트 코드 지정] -->
<script>
// --------------------------------------------------------------------------------------------------------------
// [AWS 인증 변수 선언]
const accessKey = 'AK..A6';
const secretKey = 'mP..5J';
const region = 'ap-northeast-2';
// [필요 변수 선언]
var continueSelect = null;
var innerFunction = null;
const selectAllList = [];
// --------------------------------------------------------------------------------------------------------------
// [html 최초 로드 및 이벤트 상시 대기 실시]
window.onload = async function() {
console.log("");
console.log("=========================================");
console.log("[window onload] : [start]");
console.log("=========================================");
console.log("");
try {
// -----------------------------------------
// [초기 변수 초기화]
// -----------------------------------------
continueSelect = null;
innerFunction = null;
selectAllList.length = 0;
// -----------------------------------------
// [AWS.config 지정]
// -----------------------------------------
AWS.config.update({
region: region,
accessKeyId: accessKey,
secretAccessKey: secretKey
});
// -----------------------------------------
// [AWS 객체 생성]
// -----------------------------------------
const aws = new AWS.Lambda();
// -----------------------------------------
// [내부 함수 생성]
// -----------------------------------------
innerFunction = async function() {
try {
while (true) { // 반복 조회 수행
// -----------------------------------------
// [요청 파라미터 생성]
// -----------------------------------------
var param = null;
if (continueSelect != null && continueSelect != undefined && continueSelect != ''){
param = {
MaxItems: 10, // 한번에 조회할 제한 개수
Marker: continueSelect // ✅ 반복 조회 요청
};
}
else {
param = {
MaxItems: 10 // 한번에 조회할 제한 개수
};
}
// -----------------------------------------
// Aws Lambda 람다 리스트 조회 수행
// -----------------------------------------
// AWS 참고 사이트 : https://docs.aws.amazon.com/ko_kr/lambda/latest/api/API_ListFunctions.html
// -----------------------------------------
const [err, res] = await aws.listFunctions(param).promise()
.then(data => [null, data])
.catch(error => [error, null]);
if (err) {
console.error("[aws result] : [Error] : ", err);
// [반복 조회 종료 위한 값 초기화]
continueSelect = null;
} else {
console.log("[aws result] : [Success] : ", JSON.stringify(res));
// ---------------------------------------------
// [로그 출력 예시 첨부]
// ---------------------------------------------
/*
{
"Functions": [
{
"FunctionName": "my-function-1",
"FunctionArn": "arn:aws:lambda:ap-northeast-2:123456789012:function:my-function-1",
"Runtime": "nodejs18.x",
"Role": "arn:aws:iam::123456789012:role/lambda-basic-role",
"Handler": "index.handler",
"CodeSize": 450,
"Description": "First Lambda example",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2025-11-30T02:10:30.123+0000",
"CodeSha256": "uZ1h3KDk39fjZs1LNCi6yQkPznBQ0WpgYpCv2A==",
"Version": "$LATEST",
"VpcConfig": {
"SubnetIds": [],
"SecurityGroupIds": [],
"VpcId": ""
},
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "d6c9e9d3-a7fd-4f2d-a1cd-232d839cbe81",
"PackageType": "Zip",
"Architectures": ["x86_64"],
"EphemeralStorage": {
"Size": 512
}
},
{
"FunctionName": "my-function-2",
"FunctionArn": "arn:aws:lambda:ap-northeast-2:123456789012:function:my-function-2",
"Runtime": "python3.11",
"Role": "arn:aws:iam::123456789012:role/lambda-exec-role",
"Handler": "app.lambda_handler",
"CodeSize": 1250,
"Description": "Second Lambda example",
"Timeout": 10,
"MemorySize": 256,
"LastModified": "2025-12-18T09:22:55.789+0000",
"CodeSha256": "Qak3ZI8k0IDH9d0JMlL3YnwXltFpxyIUZ6sdDg9wBfg=",
"Version": "$LATEST",
"VpcConfig": {
"SubnetIds": ["subnet-123abc", "subnet-789xyz"],
"SecurityGroupIds": ["sg-12345abcde"],
"VpcId": "vpc-123abc456"
},
"TracingConfig": {
"Mode": "Active"
},
"RevisionId": "f812be92-34dc-4711-8f5e-2e437329abc1",
"PackageType": "Zip",
"Architectures": ["arm64"],
"EphemeralStorage": {
"Size": 1024
}
}
],
"NextMarker": null
}
*/
// ---------------------------------------------
// ---------------------------------------------
// [배열에 리스트 정보 추가]
// ---------------------------------------------
const resList = res.Functions;
if (resList != null && resList != undefined){
selectAllList.push(...resList); // ✅ Array Add List
}
// ---------------------------------------------
// [반복 조회에 사용 될 정보가 있는지 확인]
// ---------------------------------------------
const resNext = res.NextMarker;
if (resNext != null && resNext != undefined && resNext != ''){
continueSelect = resNext; // ✅ Set
}
else {
continueSelect = null; // Clear
}
}
// ---------------------------------------------
// [반복 조회에 사용 될 정보가 있는지 확인 후 무한 루프 탈출 수행]
// ---------------------------------------------
if (continueSelect == null || continueSelect == undefined || continueSelect == ''){
console.error("[innerFunction] : [continueSelect] : Is Null >> Stop While True");
break;
}
else {
console.warn("[innerFunction] : [continueSelect] : Exists >> Go To While True");
}
}
console.log("");
console.log("=========================================");
console.log("[innerFunction] : Result");
console.log("---------------------------------------");
console.log("Length : ", selectAllList.length);
console.log("---------------------------------------");
console.log(JSON.stringify(selectAllList));
console.log("=========================================");
console.log("");
}
catch(exception){
console.error("[innerFunction] : [Exception] : ", exception);
}
};
// -----------------------------------------
// [내부 클로저 함수 호출]
// -----------------------------------------
await innerFunction();
// ---------------------------------------------
// [Body 표시 JSON]
// ---------------------------------------------
var resJson = {
response: "result",
data: selectAllList
}
// ---------------------------------------------
// ---------------------------------------------
// [로그 출력]
// ---------------------------------------------
document.write(JSON.stringify(resJson));
// ---------------------------------------------
}
catch (exception) {
console.error("");
console.error("=========================================");
console.error("[window onload] : [Exception] : 예외 상황 발생");
console.error("-----------------------------------------");
console.error(exception);
console.error("=========================================");
console.error("");
// ---------------------------------------------
// [Body 표시 JSON]
// ---------------------------------------------
var errJson = {
response: "exception",
data: exception.message
}
// ---------------------------------------------
// ---------------------------------------------
// [에러 출력]
// ---------------------------------------------
document.write(JSON.stringify(errJson));
// ---------------------------------------------
}
};
// --------------------------------------------------------------------------------------------------------------
</script>
</head>
<body>
</body>
</html>
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[참고 사이트]
-----------------------------------------------------------------------------------------
[AWS Lambda] Aws 람다 Python 3.13 기반 기본 함수 구조 설명 정리
https://kkh0977.tistory.com/8188
https://blog.naver.com/kkh0977/223962723156?trackingCode=blog_bloghome_searchlist
[AWS] [Lambda] 런타임 Python 3.13 - boto3 모듈 사용해 AWS Lambda 람다 함수 리스트 목록 조회
https://kkh0977.tistory.com/8286
https://blog.naver.com/kkh0977/224014658387?trackingCode=blog_bloghome_searchlist
[Aws Lambda] Aws 사이트에서 생성 된 Lambda 람다 검증 함수 리스트 및 내용 소스 코드 확인 방법
https://blog.naver.com/kkh0977/223765198383
[AWS] Lambda 람다 함수 수행 errorType Sandbox.Timedout 에러 발생
https://blog.naver.com/kkh0977/223962778768
-----------------------------------------------------------------------------------------
728x90
반응형
'JavaScript' 카테고리의 다른 글
Comments
