Skip to content

Commit e19565c

Browse files
authored
Merge pull request #227 from FullStackWithLawrence/next
add /info end point
2 parents 293dedb + 5b0c4c9 commit e19565c

File tree

11 files changed

+430
-11
lines changed

11 files changed

+430
-11
lines changed

.github/workflows/testsPython.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- name: Get IAM user info
3434
run: |
35-
aws sts get-caller-identity
35+
aws sts get-caller-identity | sed -E 's/(arn:aws:iam::)[0-9]+(:user\/\w+)/\1************\2/' | jq '.Account="************"'
3636
3737
- name: Run Python tests
3838
uses: ./.github/actions/tests/python

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## [0.8.2](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.8.1...v0.8.2) (2023-12-30)
22

3-
43
### Bug Fixes
54

6-
* refactor request templates for openai api v1 object_type ([c857082](https://github.com/FullStackWithLawrence/aws-openai/commit/c8570826c75a9f99f465ffa3ebd470795ffb70d3))
5+
- refactor request templates for openai api v1 object_type ([c857082](https://github.com/FullStackWithLawrence/aws-openai/commit/c8570826c75a9f99f465ffa3ebd470795ffb70d3))
76

87
## [0.8.1](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.8.0...v0.8.1) (2023-12-30)
98

api/terraform/api_gateway_info.tf

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
###############################################################################
2+
# REST API resources - Search
3+
# This is an HTTP Get request, to retrieve the configuration settings for the
4+
# facial recognition system.
5+
#
6+
# workflow is: 1. method request (from Postman, curl, your application, etc.)
7+
# 2. integration request (we're integrating to an AWS Lambda function)
8+
# 3. integration response (the results from the Lambda function)
9+
# 4. method response (hopefully, an http 200 response)
10+
#
11+
###############################################################################
12+
resource "aws_api_gateway_resource" "info" {
13+
path_part = "info"
14+
parent_id = aws_api_gateway_rest_api.openai.root_resource_id
15+
rest_api_id = aws_api_gateway_rest_api.openai.id
16+
}
17+
resource "aws_api_gateway_method" "info" {
18+
rest_api_id = aws_api_gateway_rest_api.openai.id
19+
resource_id = aws_api_gateway_resource.info.id
20+
http_method = "ANY"
21+
authorization = "NONE"
22+
api_key_required = "true"
23+
}
24+
25+
resource "aws_api_gateway_integration" "info" {
26+
rest_api_id = aws_api_gateway_rest_api.openai.id
27+
resource_id = aws_api_gateway_resource.info.id
28+
http_method = aws_api_gateway_method.info.http_method
29+
integration_http_method = "POST"
30+
type = "AWS_PROXY"
31+
uri = aws_lambda_function.info.invoke_arn
32+
}
33+
34+
resource "aws_lambda_permission" "info" {
35+
statement_id = "AllowExecutionFromAPIGateway"
36+
action = "lambda:InvokeFunction"
37+
function_name = aws_lambda_function.info.function_name
38+
principal = "apigateway.amazonaws.com"
39+
40+
# More: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html
41+
source_arn = "arn:aws:execute-api:${var.aws_region}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.openai.id}/*/${aws_api_gateway_method.info.http_method}${aws_api_gateway_resource.info.path}"
42+
43+
}
44+
45+
resource "aws_api_gateway_method_response" "info_response_200" {
46+
rest_api_id = aws_api_gateway_rest_api.openai.id
47+
resource_id = aws_api_gateway_resource.info.id
48+
http_method = aws_api_gateway_method.info.http_method
49+
status_code = "200"
50+
response_models = {
51+
"application/json" = "Empty"
52+
}
53+
response_parameters = {}
54+
}

api/terraform/json/iam_policy_lambda.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
"Effect": "Allow",
1919
"Action": [
2020
"apigateway:GET",
21+
"ec2:DescribeRegions",
2122
"iam:ListPolicies",
23+
"iam:ListRoles",
2224
"iam:GetPolicy",
2325
"iam:GetPolicyVersion",
2426
"iam:ListAttachedRolePolicies",
25-
"s3:ListAllMyBuckets",
26-
"ec2:DescribeRegions",
27+
"lambda:ListFunctions",
2728
"route53:ListHostedZones",
28-
"route53:ListResourceRecordSets"
29+
"route53:ListResourceRecordSets",
30+
"s3:ListAllMyBuckets"
2931
],
3032
"Resource": "*"
3133
}

api/terraform/lambda_info.tf

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#------------------------------------------------------------------------------
2+
# written by: Lawrence McDaniel
3+
# https://lawrencemcdaniel.com/
4+
#
5+
# date: dec-2023
6+
#
7+
# usage: - implement a Python Lambda function to create a dump of the
8+
# configuration settings for the facial recognition system.
9+
#------------------------------------------------------------------------------
10+
locals {
11+
info_function_name = "lambda_${var.shared_resource_identifier}_info"
12+
13+
info_build_path = "${path.module}/build/distribution_package"
14+
info_source_directory = "${path.module}/python/openai_api"
15+
info_packaging_script = "${local.info_source_directory}/create_pkg.sh"
16+
info_dist_package_name = "${local.info_function_name}_dist_pkg.zip"
17+
18+
}
19+
20+
21+
###############################################################################
22+
# Cloudwatch logging
23+
###############################################################################
24+
resource "aws_cloudwatch_log_group" "info" {
25+
name = "/aws/lambda/${local.info_function_name}"
26+
retention_in_days = var.log_retention_days
27+
tags = var.tags
28+
}
29+
30+
31+
###############################################################################
32+
# Python package
33+
# https://alek-cora-glez.medium.com/deploying-aws-lambda-function-with-terraform-custom-dependencies-7874407cd4fc
34+
###############################################################################
35+
resource "null_resource" "package_lambda_info" {
36+
triggers = {
37+
always_redeploy = timestamp()
38+
}
39+
40+
provisioner "local-exec" {
41+
interpreter = ["/bin/bash"]
42+
command = local.info_packaging_script
43+
44+
environment = {
45+
TERRAFORM_ROOT = path.module
46+
SOURCE_CODE_PATH = local.info_source_directory
47+
BUILD_PATH = local.info_build_path
48+
PACKAGE_FOLDER = local.info_function_name
49+
}
50+
}
51+
}
52+
53+
# see https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file
54+
data "archive_file" "lambda_info" {
55+
source_dir = local.info_build_path
56+
output_path = "${path.module}/build/${local.info_dist_package_name}"
57+
type = "zip"
58+
depends_on = [null_resource.package_lambda_info]
59+
60+
}
61+
62+
resource "aws_lambda_function" "info" {
63+
64+
# see https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
65+
function_name = local.info_function_name
66+
description = "OpenAI API configuration settings. invoked by API Gateway."
67+
role = aws_iam_role.lambda.arn
68+
publish = true
69+
runtime = var.lambda_python_runtime
70+
memory_size = var.lambda_memory_size
71+
timeout = var.lambda_timeout
72+
handler = "openai_api.lambda_info.lambda_handler.handler"
73+
filename = data.archive_file.lambda_info.output_path
74+
source_code_hash = data.archive_file.lambda_info.output_base64sha256
75+
layers = [aws_lambda_layer_version.genai.arn]
76+
tags = var.tags
77+
78+
environment {
79+
variables = {
80+
DEBUG_MODE = var.debug_mode
81+
AWS_DEPLOYED = true
82+
}
83+
}
84+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22
# DO NOT EDIT.
33
# Managed via automated CI/CD in .github/workflows/semanticVersionBump.yml.
4-
__version__ = "0.8.2"
4+
__version__ = "0.9.0"

0 commit comments

Comments
 (0)