Frame 19229

Panduan Praktis Membuat Fungsi Lambda

Posted by Administrator

February 19, 2026

banner

Panduan teknis untuk membuat fungsi Lambda pertama Anda menggunakan Console di AWS.

Opsi Runtime di AWS Lambda

Saat membuat fungsi di AWS Lambda pada platform Amazon Web Services, langkah pertama adalah memilih runtime.

Jika Anda memilih bahasa interpreted seperti Python atau Node.js, Anda dapat menulis dan mengedit kode fungsi langsung di console Lambda menggunakan editor bawaan. Pendekatan ini ideal untuk pengaturan cepat, pengujian, dan beban kerja kecil karena tidak memerlukan proses packaging lokal.

Namun, jika Anda menggunakan bahasa compiled seperti Java atau C#, prosesnya memerlukan langkah tambahan. Anda harus membangun aplikasi di mesin lokal, membuat deployment package, lalu mengunggah paket tersebut ke Lambda sebelum fungsi dapat dijalankan.

Mendaftar Akun AWS

Jika Anda belum memiliki akun AWS, lakukan langkah berikut untuk membuatnya.

Untuk mendaftar akun AWS:

  1. Buka https://portal.aws.amazon.com/billing/signup

  2. Ikuti petunjuk yang tersedia di layar.

Sebagian dari proses pendaftaran mencakup panggilan telepon untuk memasukkan kode verifikasi melalui keypad.

Saat Anda membuat akun AWS, sistem otomatis membuat root user. Root user memiliki akses penuh ke semua layanan dan resource dalam akun. Sebagai praktik keamanan terbaik, berikan akses administratif kepada user lain, dan gunakan root user hanya untuk tugas yang memang memerlukan akses root.

AWS akan mengirim email konfirmasi setelah proses pendaftaran selesai. Anda dapat melihat aktivitas akun dan mengelolanya kapan saja melalui https://aws.amazon.com/ dengan memilih My Account.

 

Membuat User dengan Akses Administratif

Setelah membuat akun AWS, langkah berikutnya adalah mengamankan root user, mengaktifkan AWS IAM Identity Center, serta membuat user administratif agar Anda tidak menggunakan root user untuk aktivitas sehari-hari.

Amankan Root User AWS

  1. Masuk ke AWS Management Console sebagai pemilik akun dengan memilih Root user dan memasukkan email akun AWS Anda.

  2. Masukkan password pada halaman berikutnya.

  3. Aktifkan multi-factor authentication (MFA) untuk root user Anda sesuai panduan di dokumentasi IAM.

 

Masuk sebagai User Administratif

Untuk masuk menggunakan user IAM Identity Center, gunakan URL login yang dikirim ke email Anda saat user dibuat. Ikuti panduan login di portal akses AWS jika diperlukan.

 

Memberikan Akses ke User Tambahan

Di IAM Identity Center:

  • Buat permission set sesuai praktik least privilege.

  • Tambahkan user ke dalam grup.

  • Berikan akses single sign-on pada grup tersebut.

 

Membuat Fungsi Lambda Menggunakan Console

Pada contoh ini, fungsi Anda menerima objek JSON berisi dua nilai integer bernama “length” dan “width”. Fungsi akan mengalikan kedua nilai tersebut untuk menghitung luas dan mengembalikannya sebagai string JSON.

Cara Membuat Fungsi Hello World di Console

  1. Buka halaman Functions di console Lambda.

  2. Pilih Create function.

  3. Pilih Author from scratch.

  4. Pada bagian Basic information, isi Function name dengan myLambdaFunction.

  5. Pada Runtime, pilih Node.js 24 atau Python 3.14.

  6. Biarkan arsitektur tetap x86_64, lalu pilih Create function.

Selain membuat fungsi sederhana yang mengembalikan pesan “Hello from Lambda!”, Lambda juga otomatis membuat execution role.

Execution role adalah role IAM yang memberi izin bagi fungsi Lambda untuk mengakses layanan dan resource AWS. Role yang dibuat secara otomatis memberikan izin dasar untuk menulis log ke Amazon CloudWatch.

Gunakan editor kode bawaan di console untuk mengganti kode Hello World tersebut dengan kode fungsi Anda sendiri.

 

Mengubah Kode di Console Menggunakan Node.js

1. Pilih tab Code.

Di editor kode bawaan pada console AWS Lambda, Anda akan melihat kode fungsi yang dibuat secara otomatis oleh Lambda.

Jika tab index.mjs tidak terlihat di editor kode, pilih file index.mjs pada file explorer seperti yang ditunjukkan pada diagram berikut.

Screenshot 2026 02 19 at 12.31.34

2. Paste kode berikut ke dalam tab index.mjs, lalu gantikan kode yang sebelumnya dibuat oleh AWS Lambda

Screenshot 2026 02 19 at 12.32.05

Screenshot 2026 02 19 at 12.32.21

3. Pada bagian DEPLOY, pilih Deploy untuk memperbarui kode fungsi Anda:

Screenshot 2026 02 19 at 12.33.39

 

Mengubah Kode di Console Menggunakan Python

1. Pilih tab Code.

Di editor kode bawaan pada console AWS Lambda, Anda akan melihat kode fungsi yang dibuat secara otomatis oleh Lambda.

Jika tab lambda_function.py tidak terlihat di editor kode, pilih file lambda_function.py pada file explorer seperti yang ditunjukkan pada diagram berikut.

Screenshot 2026 02 19 at 12.34.57

 

2. Paste kode berikut ke dalam tab lambda_function.py, lalu gantikan kode yang sebelumnya dibuat oleh AWS Lambda.

Screenshot 2026 02 19 at 12.35.32

 

3. Pada bagian DEPLOY, pilih Deploy untuk memperbarui kode fungsi Anda.

Screenshot 2026 02 19 at 12.33.39

 

Menjalankan (Invoke) Fungsi Lambda Menggunakan Editor Kode Console

Untuk menjalankan fungsi menggunakan editor kode di console AWS Lambda, Anda perlu membuat test event yang akan dikirim ke fungsi.

Event tersebut berupa dokumen berformat JSON yang berisi dua pasangan key-value dengan kunci “length” dan “width”.

Membuat Test Event

1. Pada bagian TEST EVENTS di editor kode console, pilih Create test event.

Screenshot 2026 02 19 at 12.38.30

2. Pada Event Name, masukkan myTestEvent.

3. Pada bagian Event JSON, ganti JSON bawaan dengan kode berikut:

{ 

Invoke the function 54 

AWS Lambda Developer Guide 

“length”: 6, 

“width”: 7 

} 

4. Pilih Save. 

 

Untuk menguji fungsi dan melihat catatan pemanggilan di bagian TEST EVENTS pada editor kode console AWS Lambda, pilih ikon Run di samping test event Anda.

Screenshot 2026 02 19 at 12.40.41

 

Setelah fungsi selesai dijalankan, respons dan log fungsi akan ditampilkan pada tab OUTPUT. Anda akan melihat hasil yang kurang lebih seperti berikut:

Node.js 

Screenshot 2026 02 19 at 12.41.29

Python

Screenshot 2026 02 19 at 12.41.56

Screenshot 2026 02 19 at 12.42.08

Saat Anda menjalankan fungsi di luar console AWS Lambda, Anda harus menggunakan Amazon CloudWatch Logs untuk melihat hasil eksekusi fungsi tersebut.

 

Melihat Catatan Eksekusi Fungsi di CloudWatch Logs

  1. Buka halaman Log groups di console CloudWatch.

  2. Pilih log group untuk fungsi Anda (/aws/lambda/myLambdaFunction). Ini adalah nama log group yang dicetak fungsi Anda ke console.

  3. Scroll ke bawah dan pilih Log stream untuk pemanggilan fungsi yang ingin Anda lihat.

Screenshot 2026 02 19 at 12.43.21

 

Anda akan melihat output yang kurang lebih seperti berikut:

Node.js 

Screenshot 2026 02 19 at 12.44.01

Pyhton

Screenshot 2026 02 19 at 12.44.32

 

Membersihkan Resource (Clean Up)

etelah selesai menggunakan fungsi contoh, Anda dapat menghapusnya. Anda juga bisa menghapus log group yang menyimpan log fungsi serta execution role yang dibuat oleh console.

Menghapus Fungsi Lambda

  1. Buka halaman Functions di console AWS Lambda.

  2. Pilih fungsi yang telah Anda buat.

  3. Pilih Actions → Delete.

  4. Ketik confirm pada kolom input, lalu pilih Delete.

Menghapus Log Group

  1. Buka halaman Log groups di console Amazon CloudWatch.

  2. Pilih log group fungsi Anda (/aws/lambda/myLambdaFunction).

  3. Pilih Actions → Delete log group(s).

  4. Pada dialog konfirmasi, pilih Delete.

Menghapus Execution Role

  1. Buka halaman Roles di console AWS Identity and Access Management.

  2. Pilih execution role fungsi Anda (misalnya myLambdaFunction-role-31exxmpl)

  3. Pilih Delete.

  4. Pada dialog konfirmasi, masukkan nama role, lalu pilih Delete.

Sumber: Dokumentasi AWS

whatsapp icon.png
Start a Conversation

Privacy & Policy

PT Central Data Technology (“CDT” or “us”) is strongly committed to ensuring that your privacy is protected as utmost importance to us. https://centraldatatech.com/ , we shall govern your use of this website, including all pages within this website (collectively referred to herein below as this “Website”), we want to contribute to providing a safe and secure environment for visitors.

The following are terms of privacy policy (“Privacy Policy”) between you (“you” or “your”) and CDT. By accessing the website, you acknowledge that you have read, understood and agree to be bound by this Privacy Policy

Use of The Subscription Service by CDT and Our Customers

When you request information from CDT and supply information that personally identifies you or allows us to contact you, you agree to disclose that information with us. CDT may disclose such information for marketing, promotional and activity only for the purpose of CDT and the Website.

Collecting Information

You are free to explore the Website without providing any personal information about yourself. When you visit the Website or register for the subscription service, we provide some navigational information for you to fill out your personal information to access some content we offered.

CDT may collect your personal data such as your name, email address, company name, phone number and other information about yourself or your business. We are collecting your data in some ways, online and offline. CDT collects your data online using features of social media, email marketing, website, and cookies technology. We may collect your data offline in events like conference, gathering, workshop, etc. However, we will not use or disclose those informations with third party or send unsolicited email to any of the addresses we collect, without your express permission. We ensure that your personal identities will only be used in accordance with this Privacy Policy.

How CDT Use the Collected Information

CDT use the information that is collected only in compliance with this privacy policy. Customers who subscribe to our subscription services are obligated through our agreements with them to comply with this Privacy Policy.

In addition to the uses of your information, we may use your personal information to:

  • Improve your browsing experience by personalizing the websites and to improve the subscription services.
  • Send information about CDT.
  • Promote our services to you and share promotional and informational content with you in accordance with your communication preferences.
  • Send information to you regarding changes to our customers’ terms of service, Privacy Policy (including the cookie policy), or other legal agreements

Cookies Technology

Cookies are small pieces of data that the site transfers to the user’s computer hard drive when the user visits the website. Cookies can record your preferences when visiting a particular site and give the advantage of identifying the interest of our visitor for statistical analysis of our site. This information can enable us to improve the content, modifying and making our site more user friendly.

Cookies were used for some reasons such as technical reasons for our website to operate. Cookies also enable us to track and target the interest of our users to enhance the experience of our website and subscription service. This data is used to deliver customized content and promotions within the Helios to customers who have an interest on particular subjects.

You have the right to decide whether to accept or refuse cookies. You can edit your cookies preferences on browser setup. If you choose to refuse the cookies, you may still use our website though your access to some functionality and areas of our website may be restricted.

This Website may also display advertisements from third parties containing links to other websites of interest. Once you have used these links to leave our site, please note that we do not have any control over the website. CDT cannot be responsible for the protection and privacy of any information that you provide while visiting such websites and this Privacy Policy does not govern such websites.

Control Your Personal Data

CDT give control to you to manage your personal data. You can request access, correction, updates or deletion of your personal information. You may unsubscribe from our marketing activity by clicking unsubscribe us from the bottom of our email or contacting us directly to remove you from our subscription list.

We will keep your personal information accurate, and we allow you to correct or change your personal identifiable information through marketing@centraldatatech.com