Files
sless/examples/hello-node/http.tf
T

40 lines
1.4 KiB
Terraform

# 2026-03-08
# http.tf — HTTP-функция: принимает запросы, возвращает приветствие.
# Код: code/handler-http.js
#
# Использование:
# terraform apply
# curl -s -X POST $(terraform output -raw trigger_url) \
# -H 'Content-Type: application/json' -d '{"name":"Naeel"}'
data "archive_file" "handler_http" {
type = "zip"
source_file = "${path.module}/code/handler-http.js"
output_path = "${path.module}/dist/handler-http.zip"
}
resource "sless_function" "hello_http" {
name = "hello-http"
runtime = "nodejs20"
entrypoint = "handler-http.handle"
memory_mb = 128
timeout_sec = 30
code_path = data.archive_file.handler_http.output_path
# filesha256 исходного файла — надёжнее чем output_md5 zip:
# MD5 zip зависит от метаданных архива и может совпасть при разном содержимом
code_hash = filesha256("${path.module}/code/handler-http.js")
}
resource "sless_trigger" "hello_http" {
name = "hello-http-trigger"
type = "http"
function = sless_function.hello_http.name
# enabled = false — чтобы заморозить функцию (не удаляя ресурс), потом поставить зновь true
enabled = true
}
output "trigger_url" {
value = sless_trigger.hello_http.url
}