new glimpse approach
This commit is contained in:
27
main.tf
27
main.tf
@@ -1,3 +1,16 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~> 5.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
region = var.region
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "assume_role" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
@@ -13,11 +26,11 @@ data "aws_iam_policy_document" "assume_role" {
|
||||
|
||||
resource "null_resource" "pip_install" {
|
||||
triggers = {
|
||||
shell_hash = "${sha256(file("${path.module}/requirements.txt"))}"
|
||||
shell_hash = "${sha256(file("${path.module}/pyproject.toml"))}"
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = "python3 -m pip install -r requirements.txt -t ${path.module}/layer/python"
|
||||
command = "uv pip compile ${path.module}/pyproject.toml --python 3.11 --no-header -o /tmp/layer-requirements.txt && uv pip install -r /tmp/layer-requirements.txt --python 3.11 -t ${path.module}/layer/python"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +42,7 @@ data "archive_file" "layer" {
|
||||
}
|
||||
|
||||
resource "aws_lambda_layer_version" "layer" {
|
||||
layer_name = "openai-layer"
|
||||
layer_name = "openai-layer-${local.env}"
|
||||
filename = data.archive_file.layer.output_path
|
||||
source_code_hash = data.archive_file.layer.output_base64sha256
|
||||
compatible_runtimes = ["python3.11"]
|
||||
@@ -38,7 +51,7 @@ resource "aws_lambda_layer_version" "layer" {
|
||||
|
||||
|
||||
resource "aws_iam_role" "iam_for_lambda" {
|
||||
name = "glimpse2"
|
||||
name = "glimpse2-${local.env}"
|
||||
assume_role_policy = data.aws_iam_policy_document.assume_role.json
|
||||
}
|
||||
|
||||
@@ -52,11 +65,11 @@ resource "aws_lambda_function" "test_lambda" {
|
||||
# If the file is not in the current working directory you will need to include a
|
||||
# path.module in the filename.
|
||||
filename = "lambda_function_payload.zip"
|
||||
function_name = "glimpse2"
|
||||
function_name = "glimpse2-${local.env}"
|
||||
role = aws_iam_role.iam_for_lambda.arn
|
||||
handler = "main.handler"
|
||||
memory_size = 512
|
||||
timeout = 30
|
||||
timeout = 60
|
||||
|
||||
source_code_hash = data.archive_file.lambda.output_base64sha256
|
||||
layers = [aws_lambda_layer_version.layer.arn]
|
||||
@@ -65,7 +78,7 @@ resource "aws_lambda_function" "test_lambda" {
|
||||
|
||||
environment {
|
||||
variables = {
|
||||
foo = "bar"
|
||||
environment = local.env
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user