Skip to content

Commit

Permalink
Update package content
Browse files Browse the repository at this point in the history
  • Loading branch information
horita-yuya committed Nov 20, 2024
1 parent 415b259 commit f2a5847
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/Publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ jobs:

- name: Prepare runtime directory
run: |
mkdir -p tlrt
mkdir -p tlrt/runtime
curl -O https://nodejs.org/dist/v20.18.0/node-v20.18.0-linux-x64.tar.xz
tar -xJf node-v20.18.0-linux-x64.tar.xz --strip-components=1
cp bin/node tlrt/runtime/node
cp bootstrap-go/build/bootstrap tlrt/runtime/bootstrap
cp compute-type-value/dist/index.js tlrt/runtime/index.js
cp terraform/aws_lambda_layer.tf tlrt/aws_lambda_layer.tf
cp terraform/tlrt_sample_index.ts tlrt/tlrt_sample_index.ts
cp terraform/tlrt_sample_lambda.tf tlrt/tlrt_sample_lambda.tf
- name: Create tar.gz and zip
run: |
Expand Down
1 change: 1 addition & 0 deletions bootstrap-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# bootstrap-go
1 change: 1 addition & 0 deletions terraform/tlrt_sample_index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type SampleHandler<EVENT extends { n1: number; n2: number }> = `Received ${EVENT["n1"]} and ${EVENT["n2"]}!`
61 changes: 61 additions & 0 deletions terraform/tlrt_sample_lambda.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
locals {
# Type Level Runtime
runtime_name = "tlrt"
}

resource "aws_lambda_function" "sample" {
function_name = "${local.runtime_name}-sample"
role = aws_iam_role.sample.arn

runtime = "provided.al2023"
handler = "${local.runtime_name}_sample_index.SampleHandler"
filename = "${path.module}/index.zip"

layers = [
aws_lambda_layer_version.tlrt.arn,
]

timeout = 600
}

resource "aws_iam_role" "sample" {
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}

data "archive_file" "sample" {
type = "zip"
source_file = "${path.module}/${local.runtime_name}_sample_index.ts"
output_path = "/tmp/index.zip"
}

data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"

principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}

actions = ["sts:AssumeRole"]
}
}

data "aws_iam_policy_document" "logging" {
statement {
effect = "Allow"

actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]

resources = ["arn:aws:logs:*:*:*"]
}
}

resource "aws_iam_role_policy" "logging" {
role = aws_iam_role.sample.id
policy = data.aws_iam_policy_document.logging.json
}
41 changes: 41 additions & 0 deletions tlrt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# How to use TLRT

1. Copy files to your project

You must copy at least the following files to your project:
- aws_lambda_layer.tf
- runtime

aws_lambda_layer.tf and runtime must be located in the same directory.

If you want to try an example, you can copy the following files:
- tlrt_sample_index.ts
- tlrt_sample_lambda.tf

These files also must be located in the same directory.

```shell
Your-Terraform-Project
├── aws_lambda_layer.tf
├── runtime
│ ├── bootstrap
│ ├── node
│ └── index.js
├── tlrt_sample_index.ts (Optional)
└── tlrt_sample_lambda.tf (Optional)
```

```shell
terraform apply

aws lambda invoke --function-name tlrt-sample --payload '{"n1": 1, "n2": 2}' --cli-binary-format raw-in-base64-out /tmp/res.json && cat /tmp/res.json
```

# TLRT Components

1. bootstrap

2. runtime
1. bootstrap
2. node
3. index.js

0 comments on commit f2a5847

Please sign in to comment.