From 6ea21f7d87daae73beeec732ddbed1dba7794cba Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 30 May 2024 21:13:47 -0700 Subject: [PATCH] initial --- .gitignore | 3 + .terraform.lock.hcl | 62 ++++++++ code/main.py | 65 +++++++++ code/schema.json | 32 ++++ main.tf | 71 +++++++++ requirements.txt | 3 + terraform.tfstate | 306 +++++++++++++++++++++++++++++++++++++++ terraform.tfstate.backup | 306 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 848 insertions(+) create mode 100644 .gitignore create mode 100644 .terraform.lock.hcl create mode 100755 code/main.py create mode 100644 code/schema.json create mode 100644 main.tf create mode 100644 requirements.txt create mode 100644 terraform.tfstate create mode 100644 terraform.tfstate.backup diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2586328 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.terraform +layer +*.zip diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..d7982ff --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,62 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/archive" { + version = "2.4.2" + hashes = [ + "h1:G4v6F6Lhqlo3EKGBKEK/kJRhNcQiRrhEdUiVpBHKHOA=", + "zh:08faed7c9f42d82bc3d406d0d9d4971e2d1c2d34eae268ad211b8aca57b7f758", + "zh:3564112ed2d097d7e0672378044a69b06642c326f6f1584d81c7cdd32ebf3a08", + "zh:53cd9afd223c15828c1916e68cb728d2be1cbccb9545568d6c2b122d0bac5102", + "zh:5ae4e41e3a1ce9d40b6458218a85bbde44f21723943982bca4a3b8bb7c103670", + "zh:5b65499218b315b96e95c5d3463ea6d7c66245b59461217c99eaa1611891cd2c", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7f45b35a8330bebd184c2545a41782ff58240ed6ba947274d9881dd5da44b02e", + "zh:87e67891033214e55cfead1391d68e6a3bf37993b7607753237e82aa3250bb71", + "zh:de3590d14037ad81fc5cedf7cfa44614a92452d7b39676289b704a962050bc5e", + "zh:e7e6f2ea567f2dbb3baa81c6203be69f9cd6aeeb01204fd93e3cf181e099b610", + "zh:fd24d03c89a7702628c2e5a3c732c0dede56fa75a08da4a1efe17b5f881c88e2", + "zh:febf4b7b5f3ff2adff0573ef6361f09b6638105111644bdebc0e4f575373935f", + ] +} + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.52.0" + hashes = [ + "h1:Z+mvggOAJJdEwf2p2fxT6WUW0Pch8Ky+LhsZa1TdqFg=", + "zh:22c4599d47cd59e5519c52afc528fa2aec43b4434f369870ee2806daa071449d", + "zh:3c2edc482662a654f84db4cd3f2cdd8f200147207d053d2e95082744b7814e6d", + "zh:57edc36f908c64de37e92a978f3d675604315a725268da936fcd1e270199db47", + "zh:79e7afd5fb161f2eb2b7f8e7fd5cbb7f56a2c64f141b56f511ec69337ad3e96b", + "zh:82c6ae9a7f971b6ee8c476b6eb7f1be9d24ddd183cbf025f52628084ddb3a5ae", + "zh:92faecc0a8f573f57f37d24415862380a40341eb13d66beb738dd0873899a58e", + "zh:963d3c0e1aa22c872cd96f04ceb41c388137b972f714efbde989221bf7f6f723", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:af6d3bb94aa8a84d740e3731d2379cc5e12aa48d5db0f7489c4639f3814a22d7", + "zh:b9f7aceeaf5daf71394eab9bf0f9f56fdc762cac90e4d62e63aa3fcdf6c1c127", + "zh:c3dcfc2569edae4f36b798c76da7f7633e7bf322505d447d7c370a56c2a30dd2", + "zh:c8abb21c5ceba857f0eaff9e531d781dc655f8cdfae1cf056066daae72546a7f", + "zh:d92004a6a2a770d2542fd9c01b685418ab8d7ab422cf2cdce35dde789bc8593c", + "zh:dc794660b1d6d8f26a917e0ffab1875aa75144736875efaa60f29c72bf02afbf", + "zh:df931c4905e35ae43d558f6cda15f05710a7a24ecbb94533f8822e7572126512", + ] +} + +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.2" + hashes = [ + "h1:zT1ZbegaAYHwQa+QwIFugArWikRJI9dqohj8xb0GY88=", + "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", + "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", + "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", + "zh:4c2f1faee67af104f5f9e711c4574ff4d298afaa8a420680b0cb55d7bbc65606", + "zh:544b33b757c0b954dbb87db83a5ad921edd61f02f1dc86c6186a5ea86465b546", + "zh:696cf785090e1e8cf1587499516b0494f47413b43cb99877ad97f5d0de3dc539", + "zh:6e301f34757b5d265ae44467d95306d61bef5e41930be1365f5a8dcf80f59452", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:913a929070c819e59e94bb37a2a253c228f83921136ff4a7aa1a178c7cce5422", + "zh:aa9015926cd152425dbf86d1abdbc74bfe0e1ba3d26b3db35051d7b9ca9f72ae", + "zh:bb04798b016e1e1d49bcc76d62c53b56c88c63d6f2dfe38821afef17c416a0e1", + "zh:c23084e1b23577de22603cff752e59128d83cfecc2e6819edadd8cf7a10af11e", + ] +} diff --git a/code/main.py b/code/main.py new file mode 100755 index 0000000..52e65b8 --- /dev/null +++ b/code/main.py @@ -0,0 +1,65 @@ + +#!/usr/bin/env python3 +import openai +import json + +openai.api_key = "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" +def slurp_file(filename): + with open(filename, 'r') as file: + data = file.read() + return data + +BASE_PROMPT="""You extract invoice details from pdfs. Always follow this json schema. Do not respond with anything except the raw json response. Do not respond in code blocks(```). +``` +{} +``` +""".format(slurp_file('schema.json')) + +import sys +# context = sys.argv[1] +# problem = sys.argv[2] +# other = sys.argv[3] +client = openai.OpenAI(api_key= "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") +client.api_key = "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" +def handler(event, context): + assistant = client.beta.assistants.create( + name="pdf-reader", + instructions=BASE_PROMPT, + model="gpt-4o", + tools=[{"type": "file_search"}], + ) + import urllib.request + + url = event.url + with urllib.request.urlopen(url) as response: + data = response.read() + with open("/tmp/test.pdf", "wb") as f: + f.write(data) + + # Upload the user provided file to OpenAI + message_file = client.files.create( + file=open("/tmp/test.pdf", "rb"), purpose="assistants" + ) + + # Create a thread and attach the file to the message + thread = client.beta.threads.create( + messages=[ + { + "role": "user", + "content": "extract the details from this invoice", + # Attach the new file to the message. + "attachments": [ + { "file_id": message_file.id, "tools": [{"type": "file_search"}] } + ], + } + ] + ) + run = client.beta.threads.runs.create_and_poll( + thread_id=thread.id, assistant_id=assistant.id + ) + + messages = list(client.beta.threads.messages.list(thread_id=thread.id, run_id=run.id)) + + print(run.usage) + + return json.loads(messages[0].content[0].text.value) \ No newline at end of file diff --git a/code/schema.json b/code/schema.json new file mode 100644 index 0000000..2783311 --- /dev/null +++ b/code/schema.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Invoice Data Schema", + "description": "A schema to validate invoice data", + "type": "object", + "properties": { + "customer_identifier": { + "description": "The customer's name. e.g., ABC Corporation, Microsoft, etc.", + "type": "string" + }, + "date": { + "description": "Invoice date in ISO 8601 format (YYYY-MM-DD).", + "type": "string", + "format": "date" + }, + "invoice_number": { + "description": "Unique invoice number for the transaction.", + "type": "string" + }, + "account_number": { + "description": "Customer's account number associated with the invoice.", + "type": "string" + }, + "total": { + "description": "Total amount of the invoice, including taxes and fees. It should be a decimal number as a string.", + "type": "string", + "pattern": "^\\d+(\\.\\d{1,2})?$" + } + }, + "required": ["customer_identifier", "date", "invoice_number", "account_number", "total"], + "additionalProperties": false +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..3391ef1 --- /dev/null +++ b/main.tf @@ -0,0 +1,71 @@ +data "aws_iam_policy_document" "assume_role" { + statement { + effect = "Allow" + + principals { + type = "Service" + identifiers = ["lambda.amazonaws.com"] + } + + actions = ["sts:AssumeRole"] + } +} + +resource "null_resource" "pip_install" { + triggers = { + shell_hash = "${sha256(file("${path.module}/requirements.txt"))}" + } + + provisioner "local-exec" { + command = "python3 -m pip install -r requirements.txt -t ${path.module}/layer/python" + } +} + +data "archive_file" "layer" { + type = "zip" + source_dir = "${path.module}/layer" + output_path = "${path.module}/layer.zip" + depends_on = [null_resource.pip_install] +} + +resource "aws_lambda_layer_version" "layer" { + layer_name = "openai-layer" + filename = data.archive_file.layer.output_path + source_code_hash = data.archive_file.layer.output_base64sha256 + compatible_runtimes = ["python3.11"] +} + + + +resource "aws_iam_role" "iam_for_lambda" { + name = "glimpse2" + assume_role_policy = data.aws_iam_policy_document.assume_role.json +} + +data "archive_file" "lambda" { + type = "zip" + source_dir = "./code" + output_path = "lambda_function_payload.zip" +} + +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" + role = aws_iam_role.iam_for_lambda.arn + handler = "main.handler" + memory_size = 512 + timeout = 30 + + source_code_hash = data.archive_file.lambda.output_base64sha256 + layers = [aws_lambda_layer_version.layer.arn] + + runtime = "python3.11" + + environment { + variables = { + foo = "bar" + } + } +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..74d2ac8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +openai==1.30.4 +pydantic==2.5.3 +pydantic_core==2.14.6 \ No newline at end of file diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 0000000..84c257c --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,306 @@ +{ + "version": 4, + "terraform_version": "1.8.3", + "serial": 36, + "lineage": "3d9e9e5b-e59a-3f03-49c9-906d67028b61", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "archive_file", + "name": "lambda", + "provider": "provider[\"registry.terraform.io/hashicorp/archive\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "exclude_symlink_directories": null, + "excludes": null, + "id": "e0f5cbbaf15ba9f6bd489db9345bb5583713008d", + "output_base64sha256": "kAea/gClyQLrEU+ooG5R0S18OT/nheJiIrxvecC1LrA=", + "output_base64sha512": "dC70fiIcas64eAphZGf2ggIF0VyqhSfz1yELssjFL096AnlN5RwRuL44uq5ovdxWME/I9zLTal4IpD4lDqf+FA==", + "output_file_mode": null, + "output_md5": "3ef9dc50a088c997910c16c62d690a03", + "output_path": "lambda_function_payload.zip", + "output_sha": "e0f5cbbaf15ba9f6bd489db9345bb5583713008d", + "output_sha256": "90079afe00a5c902eb114fa8a06e51d12d7c393fe785e26222bc6f79c0b52eb0", + "output_sha512": "742ef47e221c6aceb8780a616467f6820205d15caa8527f3d7210bb2c8c52f4f7a02794de51c11b8be38baae68bddc56304fc8f732d36a5e08a43e250ea7fe14", + "output_size": 1817, + "source": [], + "source_content": null, + "source_content_filename": null, + "source_dir": "./code", + "source_file": null, + "type": "zip" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "archive_file", + "name": "layer", + "provider": "provider[\"registry.terraform.io/hashicorp/archive\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "exclude_symlink_directories": null, + "excludes": null, + "id": "c55daed5f392052aaa8550df15c7586bce956ff1", + "output_base64sha256": "CuqYP2g/IJX/YEnvN0hGrQNhdx1SAn1+/abBHcJMcXU=", + "output_base64sha512": "JRCt30sfQZk7muptBMvnzTwZuQedr1R1S66uz4oMfaXRyAfu+knLuEzAiVX6MLvk1bwlcFNpTznsS8ZuiKJTOQ==", + "output_file_mode": null, + "output_md5": "a382299daf7c39c0065eb8a03397f1af", + "output_path": "./layer.zip", + "output_sha": "c55daed5f392052aaa8550df15c7586bce956ff1", + "output_sha256": "0aea983f683f2095ff6049ef374846ad0361771d52027d7efda6c11dc24c7175", + "output_sha512": "2510addf4b1f41993b9aea6d04cbe7cd3c19b9079daf54754baeaecf8a0c7da5d1c807eefa49cbb84cc08955fa30bbe4d5bc257053694f39ec4bc66e88a25339", + "output_size": 5819274, + "source": [], + "source_content": null, + "source_content_filename": null, + "source_dir": "./layer", + "source_file": null, + "type": "zip" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "aws_iam_policy_document", + "name": "assume_role", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "2690255455", + "json": "{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": \"sts:AssumeRole\",\n \"Principal\": {\n \"Service\": \"lambda.amazonaws.com\"\n }\n }\n ]\n}", + "minified_json": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"}}]}", + "override_json": null, + "override_policy_documents": null, + "policy_id": null, + "source_json": null, + "source_policy_documents": null, + "statement": [ + { + "actions": [ + "sts:AssumeRole" + ], + "condition": [], + "effect": "Allow", + "not_actions": [], + "not_principals": [], + "not_resources": [], + "principals": [ + { + "identifiers": [ + "lambda.amazonaws.com" + ], + "type": "Service" + } + ], + "resources": [], + "sid": "" + } + ], + "version": "2012-10-17" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "aws_iam_role", + "name": "iam_for_lambda", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::679918342773:role/glimpse2", + "assume_role_policy": "{\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"}}],\"Version\":\"2012-10-17\"}", + "create_date": "2024-05-31T03:45:29Z", + "description": "", + "force_detach_policies": false, + "id": "glimpse2", + "inline_policy": [], + "managed_policy_arns": [], + "max_session_duration": 3600, + "name": "glimpse2", + "name_prefix": "", + "path": "/", + "permissions_boundary": "", + "tags": {}, + "tags_all": {}, + "unique_id": "AROAZ4TSKSJ2TJAOEIZDG" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "data.aws_iam_policy_document.assume_role" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_lambda_function", + "name": "test_lambda", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "architectures": [ + "x86_64" + ], + "arn": "arn:aws:lambda:us-east-1:679918342773:function:glimpse2", + "code_sha256": "kAea/gClyQLrEU+ooG5R0S18OT/nheJiIrxvecC1LrA=", + "code_signing_config_arn": "", + "dead_letter_config": [], + "description": "", + "environment": [ + { + "variables": { + "foo": "bar" + } + } + ], + "ephemeral_storage": [ + { + "size": 512 + } + ], + "file_system_config": [], + "filename": "lambda_function_payload.zip", + "function_name": "glimpse2", + "handler": "main.handler", + "id": "glimpse2", + "image_config": [], + "image_uri": "", + "invoke_arn": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:679918342773:function:glimpse2/invocations", + "kms_key_arn": "", + "last_modified": "2024-05-31T04:11:26.000+0000", + "layers": [ + "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer:3" + ], + "logging_config": [ + { + "application_log_level": "", + "log_format": "Text", + "log_group": "/aws/lambda/glimpse2", + "system_log_level": "" + } + ], + "memory_size": 512, + "package_type": "Zip", + "publish": false, + "qualified_arn": "arn:aws:lambda:us-east-1:679918342773:function:glimpse2:$LATEST", + "qualified_invoke_arn": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:679918342773:function:glimpse2:$LATEST/invocations", + "replace_security_groups_on_destroy": null, + "replacement_security_group_ids": null, + "reserved_concurrent_executions": -1, + "role": "arn:aws:iam::679918342773:role/glimpse2", + "runtime": "python3.11", + "s3_bucket": null, + "s3_key": null, + "s3_object_version": null, + "signing_job_arn": "", + "signing_profile_version_arn": "", + "skip_destroy": false, + "snap_start": [], + "source_code_hash": "kAea/gClyQLrEU+ooG5R0S18OT/nheJiIrxvecC1LrA=", + "source_code_size": 1817, + "tags": {}, + "tags_all": {}, + "timeout": 30, + "timeouts": null, + "tracing_config": [ + { + "mode": "PassThrough" + } + ], + "version": "$LATEST", + "vpc_config": [] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwLCJ1cGRhdGUiOjYwMDAwMDAwMDAwMH19", + "dependencies": [ + "aws_iam_role.iam_for_lambda", + "aws_lambda_layer_version.layer", + "data.archive_file.lambda", + "data.archive_file.layer", + "data.aws_iam_policy_document.assume_role", + "null_resource.pip_install" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_lambda_layer_version", + "name": "layer", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer:3", + "code_sha256": "CuqYP2g/IJX/YEnvN0hGrQNhdx1SAn1+/abBHcJMcXU=", + "compatible_architectures": [], + "compatible_runtimes": [ + "python3.11" + ], + "created_date": "2024-05-31T04:04:35.368+0000", + "description": "", + "filename": "./layer.zip", + "id": "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer:3", + "layer_arn": "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer", + "layer_name": "openai-layer", + "license_info": "", + "s3_bucket": null, + "s3_key": null, + "s3_object_version": null, + "signing_job_arn": "", + "signing_profile_version_arn": "", + "skip_destroy": false, + "source_code_hash": "CuqYP2g/IJX/YEnvN0hGrQNhdx1SAn1+/abBHcJMcXU=", + "source_code_size": 5819274, + "version": "3" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "data.archive_file.layer", + "null_resource.pip_install" + ] + } + ] + }, + { + "mode": "managed", + "type": "null_resource", + "name": "pip_install", + "provider": "provider[\"registry.terraform.io/hashicorp/null\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "1021063493210559277", + "triggers": { + "shell_hash": "6a99f45c27ef7e94781d92867edc01407a37d8a5ff68e4dcf245f4ec82154993" + } + }, + "sensitive_attributes": [] + } + ] + } + ], + "check_results": null +} diff --git a/terraform.tfstate.backup b/terraform.tfstate.backup new file mode 100644 index 0000000..1c721eb --- /dev/null +++ b/terraform.tfstate.backup @@ -0,0 +1,306 @@ +{ + "version": 4, + "terraform_version": "1.8.3", + "serial": 34, + "lineage": "3d9e9e5b-e59a-3f03-49c9-906d67028b61", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "archive_file", + "name": "lambda", + "provider": "provider[\"registry.terraform.io/hashicorp/archive\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "exclude_symlink_directories": null, + "excludes": null, + "id": "cd2da52ee06f5a5ebcb7268242d15663c75bb601", + "output_base64sha256": "Jks5sSegvcGcJtmhgSv+46jgP/Z5htIgnKRonNQyNHM=", + "output_base64sha512": "L8ytVDZYU9x9C6kchibgDbJF81HDp5xRqJB029ISzsqHtvqGMdCI6Isy+pBnx0x0CVdstv88OyHXjVci/J2v+w==", + "output_file_mode": null, + "output_md5": "7ead91cdc01b34ae233fc6c269422a51", + "output_path": "lambda_function_payload.zip", + "output_sha": "cd2da52ee06f5a5ebcb7268242d15663c75bb601", + "output_sha256": "264b39b127a0bdc19c26d9a1812bfee3a8e03ff67986d2209ca4689cd4323473", + "output_sha512": "2fccad54365853dc7d0ba91c8626e00db245f351c3a79c51a89074dbd212ceca87b6fa8631d088e88b32fa9067c74c7409576cb6ff3c3b21d78d5722fc9daffb", + "output_size": 1810, + "source": [], + "source_content": null, + "source_content_filename": null, + "source_dir": "./code", + "source_file": null, + "type": "zip" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "archive_file", + "name": "layer", + "provider": "provider[\"registry.terraform.io/hashicorp/archive\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "exclude_symlink_directories": null, + "excludes": null, + "id": "c55daed5f392052aaa8550df15c7586bce956ff1", + "output_base64sha256": "CuqYP2g/IJX/YEnvN0hGrQNhdx1SAn1+/abBHcJMcXU=", + "output_base64sha512": "JRCt30sfQZk7muptBMvnzTwZuQedr1R1S66uz4oMfaXRyAfu+knLuEzAiVX6MLvk1bwlcFNpTznsS8ZuiKJTOQ==", + "output_file_mode": null, + "output_md5": "a382299daf7c39c0065eb8a03397f1af", + "output_path": "./layer.zip", + "output_sha": "c55daed5f392052aaa8550df15c7586bce956ff1", + "output_sha256": "0aea983f683f2095ff6049ef374846ad0361771d52027d7efda6c11dc24c7175", + "output_sha512": "2510addf4b1f41993b9aea6d04cbe7cd3c19b9079daf54754baeaecf8a0c7da5d1c807eefa49cbb84cc08955fa30bbe4d5bc257053694f39ec4bc66e88a25339", + "output_size": 5819274, + "source": [], + "source_content": null, + "source_content_filename": null, + "source_dir": "./layer", + "source_file": null, + "type": "zip" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "aws_iam_policy_document", + "name": "assume_role", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "2690255455", + "json": "{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": \"sts:AssumeRole\",\n \"Principal\": {\n \"Service\": \"lambda.amazonaws.com\"\n }\n }\n ]\n}", + "minified_json": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"}}]}", + "override_json": null, + "override_policy_documents": null, + "policy_id": null, + "source_json": null, + "source_policy_documents": null, + "statement": [ + { + "actions": [ + "sts:AssumeRole" + ], + "condition": [], + "effect": "Allow", + "not_actions": [], + "not_principals": [], + "not_resources": [], + "principals": [ + { + "identifiers": [ + "lambda.amazonaws.com" + ], + "type": "Service" + } + ], + "resources": [], + "sid": "" + } + ], + "version": "2012-10-17" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "aws_iam_role", + "name": "iam_for_lambda", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:iam::679918342773:role/glimpse2", + "assume_role_policy": "{\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"}}],\"Version\":\"2012-10-17\"}", + "create_date": "2024-05-31T03:45:29Z", + "description": "", + "force_detach_policies": false, + "id": "glimpse2", + "inline_policy": [], + "managed_policy_arns": [], + "max_session_duration": 3600, + "name": "glimpse2", + "name_prefix": "", + "path": "/", + "permissions_boundary": "", + "tags": {}, + "tags_all": {}, + "unique_id": "AROAZ4TSKSJ2TJAOEIZDG" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "data.aws_iam_policy_document.assume_role" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_lambda_function", + "name": "test_lambda", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "architectures": [ + "x86_64" + ], + "arn": "arn:aws:lambda:us-east-1:679918342773:function:glimpse2", + "code_sha256": "Jks5sSegvcGcJtmhgSv+46jgP/Z5htIgnKRonNQyNHM=", + "code_signing_config_arn": "", + "dead_letter_config": [], + "description": "", + "environment": [ + { + "variables": { + "foo": "bar" + } + } + ], + "ephemeral_storage": [ + { + "size": 512 + } + ], + "file_system_config": [], + "filename": "lambda_function_payload.zip", + "function_name": "glimpse2", + "handler": "main.handler", + "id": "glimpse2", + "image_config": [], + "image_uri": "", + "invoke_arn": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:679918342773:function:glimpse2/invocations", + "kms_key_arn": "", + "last_modified": "2024-05-31T04:10:40.000+0000", + "layers": [ + "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer:3" + ], + "logging_config": [ + { + "application_log_level": "", + "log_format": "Text", + "log_group": "/aws/lambda/glimpse2", + "system_log_level": "" + } + ], + "memory_size": 512, + "package_type": "Zip", + "publish": false, + "qualified_arn": "arn:aws:lambda:us-east-1:679918342773:function:glimpse2:$LATEST", + "qualified_invoke_arn": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:679918342773:function:glimpse2:$LATEST/invocations", + "replace_security_groups_on_destroy": null, + "replacement_security_group_ids": null, + "reserved_concurrent_executions": -1, + "role": "arn:aws:iam::679918342773:role/glimpse2", + "runtime": "python3.11", + "s3_bucket": null, + "s3_key": null, + "s3_object_version": null, + "signing_job_arn": "", + "signing_profile_version_arn": "", + "skip_destroy": false, + "snap_start": [], + "source_code_hash": "Jks5sSegvcGcJtmhgSv+46jgP/Z5htIgnKRonNQyNHM=", + "source_code_size": 1810, + "tags": {}, + "tags_all": {}, + "timeout": 30, + "timeouts": null, + "tracing_config": [ + { + "mode": "PassThrough" + } + ], + "version": "$LATEST", + "vpc_config": [] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6NjAwMDAwMDAwMDAwLCJ1cGRhdGUiOjYwMDAwMDAwMDAwMH19", + "dependencies": [ + "aws_iam_role.iam_for_lambda", + "aws_lambda_layer_version.layer", + "data.archive_file.lambda", + "data.archive_file.layer", + "data.aws_iam_policy_document.assume_role", + "null_resource.pip_install" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_lambda_layer_version", + "name": "layer", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer:3", + "code_sha256": "CuqYP2g/IJX/YEnvN0hGrQNhdx1SAn1+/abBHcJMcXU=", + "compatible_architectures": [], + "compatible_runtimes": [ + "python3.11" + ], + "created_date": "2024-05-31T04:04:35.368+0000", + "description": "", + "filename": "./layer.zip", + "id": "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer:3", + "layer_arn": "arn:aws:lambda:us-east-1:679918342773:layer:openai-layer", + "layer_name": "openai-layer", + "license_info": "", + "s3_bucket": null, + "s3_key": null, + "s3_object_version": null, + "signing_job_arn": "", + "signing_profile_version_arn": "", + "skip_destroy": false, + "source_code_hash": "CuqYP2g/IJX/YEnvN0hGrQNhdx1SAn1+/abBHcJMcXU=", + "source_code_size": 5819274, + "version": "3" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "data.archive_file.layer", + "null_resource.pip_install" + ] + } + ] + }, + { + "mode": "managed", + "type": "null_resource", + "name": "pip_install", + "provider": "provider[\"registry.terraform.io/hashicorp/null\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "1021063493210559277", + "triggers": { + "shell_hash": "6a99f45c27ef7e94781d92867edc01407a37d8a5ff68e4dcf245f4ec82154993" + } + }, + "sensitive_attributes": [] + } + ] + } + ], + "check_results": null +}