Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the resume email flow. #61

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
aws ecr describe-repositories --repository-names ${{ vars.EMAIL_REQUEST_PROCESSOR_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.EMAIL_REQUEST_PROCESSOR_ECR_NAME }}
aws ecr describe-repositories --repository-names ${{ vars.EMAIL_REQUEST_PREPROCESSOR_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.EMAIL_REQUEST_PREPROCESSOR_ECR_NAME }}
aws ecr describe-repositories --repository-names ${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }}
aws ecr describe-repositories --repository-names ${{ vars.ATTACHMENT_SAVER_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.ATTACHMENT_SAVER_ECR_NAME }}
aws ecr describe-repositories --repository-names ${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }}
aws ecr describe-repositories --repository-names ${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }}
aws ecr describe-repositories --repository-names ${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }}
aws ecr describe-repositories --repository-names ${{ vars.RESUME_ECR_NAME }} || aws ecr create-repository --repository-name ${{ vars.RESUME_ECR_NAME }}

- name: Generate timestamp
id: timestamp
Expand Down Expand Up @@ -64,6 +69,16 @@ jobs:
docker push $ECR_REGISTRY/${{ vars.EMAIL_REQUEST_PREPROCESSOR_ECR_NAME }}:$IMAGE_TAG
docker build -t $ECR_REGISTRY/${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }}:$IMAGE_TAG ./lambdas/EmailProcessor/EmailResponseProcessorFunction
docker push $ECR_REGISTRY/${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }}:$IMAGE_TAG
docker build -t $ECR_REGISTRY/${{ vars.ATTACHMENT_SAVER_ECR_NAME }}:$IMAGE_TAG ./lambdas/AttachmentSaver/AttachmentSaverFunction
docker push $ECR_REGISTRY/${{ vars.ATTACHMENT_SAVER_ECR_NAME }}:$IMAGE_TAG
docker build -t $ECR_REGISTRY/${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }}:$IMAGE_TAG ./lambdas/TranscriptionProcessor/TranscriptionFunction
docker push $ECR_REGISTRY/${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }}:$IMAGE_TAG
docker build -t $ECR_REGISTRY/${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }}:$IMAGE_TAG ./lambdas/ResumeProcessor/ResumeRequestProcessorFunction
docker push $ECR_REGISTRY/${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }}:$IMAGE_TAG
docker build -t $ECR_REGISTRY/${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }}:$IMAGE_TAG ./lambdas/ResumeProcessor/ResumeRequestPreProcessorFunction
docker push $ECR_REGISTRY/${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }}:$IMAGE_TAG
docker build -t $ECR_REGISTRY/${{ vars.RESUME_ECR_NAME }}:$IMAGE_TAG ./lambdas/ResumeProcessor/ResumeFunction
docker push $ECR_REGISTRY/${{ vars.RESUME_ECR_NAME }}:$IMAGE_TAG

terraform_plan:
if: github.event_name == 'pull_request'
Expand Down Expand Up @@ -112,6 +127,11 @@ jobs:
-var="email_response_processor_lambda_repository_name=${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }}" \
-var="sender_email=${{ vars.SENDER_EMAIL }}" \
-var="chat_rule_recipient=${{ vars.CHAT_RULE_RECIPIENT }}" \
-var="attachment_saver_lambda_repository_name=${{ vars.ATTACHMENT_SAVER_ECR_NAME }}" \
-var="transcription_processor_lambda_repository_name=${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }}" \
-var="resume_request_processor_lambda_repository_name=${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }}" \
-var="resume_request_preprocessor_lambda_repository_name=${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }}" \
-var="resume_lambda_repository_name=${{ vars.RESUME_ECR_NAME }}" \
-no-color -out=terraform.tfplan

- name: Upload Terraform Plan
Expand Down Expand Up @@ -200,6 +220,11 @@ jobs:
for digest in $(aws ecr list-images --repository-name ${{ vars.EMAIL_REQUEST_PROCESSOR_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.EMAIL_REQUEST_PROCESSOR_ECR_NAME }} --image-ids imageDigest=$digest; done
for digest in $(aws ecr list-images --repository-name ${{ vars.EMAIL_REQUEST_PREPROCESSOR_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.EMAIL_REQUEST_PREPROCESSOR_ECR_NAME }} --image-ids imageDigest=$digest; done
for digest in $(aws ecr list-images --repository-name ${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }} --image-ids imageDigest=$digest; done
for digest in $(aws ecr list-images --repository-name ${{ vars.ATTACHMENT_SAVER_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.ATTACHMENT_SAVER_ECR_NAME }} --image-ids imageDigest=$digest; done
for digest in $(aws ecr list-images --repository-name ${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }} --image-ids imageDigest=$digest; done
for digest in $(aws ecr list-images --repository-name ${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }} --image-ids imageDigest=$digest; done
for digest in $(aws ecr list-images --repository-name ${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }} --image-ids imageDigest=$digest; done
for digest in $(aws ecr list-images --repository-name ${{ vars.RESUME_ECR_NAME }} --query 'sort_by(imageIds,&imagePushedAt)[0:-2].imageDigest' --output text); do aws ecr batch-delete-image --repository-name ${{ vars.RESUME_ECR_NAME }} --image-ids imageDigest=$digest; done

deploy-infra:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand Down Expand Up @@ -236,6 +261,11 @@ jobs:
-var="email_response_processor_lambda_repository_name=${{ vars.EMAIL_RESPONSE_PROCESSOR_ECR_NAME }}" \
-var="sender_email=${{ vars.SENDER_EMAIL }}" \
-var="chat_rule_recipient=${{ vars.CHAT_RULE_RECIPIENT }}" \
-var="attachment_saver_lambda_repository_name=${{ vars.ATTACHMENT_SAVER_ECR_NAME }}" \
-var="transcription_processor_lambda_repository_name=${{ vars.TRANSCRIPTION_PROCESSOR_ECR_NAME }}" \
-var="resume_request_processor_lambda_repository_name=${{ vars.RESUME_REQUEST_PROCESSOR_ECR_NAME }}" \
-var="resume_request_preprocessor_lambda_repository_name=${{ vars.RESUME_REQUEST_PREPROCESSOR_ECR_NAME }}" \
-var="resume_lambda_repository_name=${{ vars.RESUME_ECR_NAME }}" \
-auto-approve -no-color -input=false


8 changes: 8 additions & 0 deletions lambdas/AttachmentSaver/AttachmentSaver.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
15 changes: 15 additions & 0 deletions lambdas/AttachmentSaver/AttachmentSaverFunction/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM public.ecr.aws/sam/build-java17:latest as build-image

WORKDIR "/task"
COPY src/ src/
COPY pom.xml ./

RUN mvn -q clean install
RUN mvn dependency:copy-dependencies -DincludeScope=compile

FROM public.ecr.aws/lambda/java:17

COPY --from=build-image /task/target/classes /var/task/
COPY --from=build-image /task/target/dependency /var/task/lib
# Command can be overwritten by providing a different command in the template directly.
CMD ["com.levio.awsdemo.attachmentsaver.App::handleRequest"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.levio.aws-demo</groupId>
<artifactId>attachment-saver</artifactId>
<name>Attachment Saver</name>
<version>1.0</version>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration />
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>
</project>
38 changes: 38 additions & 0 deletions lambdas/AttachmentSaver/AttachmentSaverFunction/events/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"Records": [
{
"eventVersion": "2.0",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "1970-01-01T00:00:00.000Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"responseElements": {
"x-amz-request-id": "EXAMPLE123456789",
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "testConfigRule",
"bucket": {
"name": "levio-demo-fev-esta-ses-bucket-dev",
"ownerIdentity": {
"principalId": "EXAMPLE"
},
"arn": "arn:aws:s3:::example-bucket"
},
"object": {
"key": "resume/email/u987v5umtglfcd0gm92traijlp7vqq44g8uat401",
"size": 1024,
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901"
}
}
}
]
}
71 changes: 71 additions & 0 deletions lambdas/AttachmentSaver/AttachmentSaverFunction/iac/lambda.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
data "aws_ecr_image" "lambda_image" {
repository_name = var.lambda_repository_name
most_recent = true
}

data "aws_caller_identity" "current" {}

module "lambda_function_container_image" {
timeout = 60
source = "terraform-aws-modules/lambda/aws"
function_name = var.lambda_function_name
create_package = false
image_uri = data.aws_ecr_image.lambda_image.image_uri
package_type = "Image"
memory_size = 1024
role_name = "${var.lambda_function_name}-role"
attach_policy_statements = true

environment_variables = {
}

policy_statements = {
log_group = {
effect = "Allow"
actions = [
"logs:CreateLogGroup"
]
resources = [
"arn:aws:logs:*:*:*"
]
}

log_write = {
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
]
resources = [
"arn:aws:logs:*:*:log-group:/aws/${var.lambda_function_name}/*:*"
]
}

s3 = {
effect = "Allow"
actions = [
"s3:Get*",
"s3:List*",
"s3:Describe*",
"s3:PutObject",
"s3-object-lambda:Get*",
"s3-object-lambda:List*",
"s3-object-lambda:WriteGetObjectResponse"
]
resources = [
var.ses_bucket_arn,
"${var.ses_bucket_arn}/*"
]
}
}

create_current_version_allowed_triggers = false

allowed_triggers = {
s3 = {
principal = "s3.amazonaws.com"
source_arn = var.ses_bucket_arn
}
}

}
3 changes: 3 additions & 0 deletions lambdas/AttachmentSaver/AttachmentSaverFunction/iac/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "lambda_function_arn" {
value = module.lambda_function_container_image.lambda_function_arn
}
24 changes: 24 additions & 0 deletions lambdas/AttachmentSaver/AttachmentSaverFunction/iac/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
variable "lambda_function_name" {
type = string
nullable = false
}

variable "lambda_repository_name" {
type = string
nullable = false
}

variable "ses_bucket_name" {
type = string
nullable = false
}

variable "ses_bucket_arn" {
type = string
nullable = false
}

variable "aws_region" {
type = string
default = "us-east-1"
}
82 changes: 82 additions & 0 deletions lambdas/AttachmentSaver/AttachmentSaverFunction/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.levio.aws-demo</groupId>
<artifactId>attachment-saver</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Attachment Saver</name>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.20.52</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
<version>2.20.52</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading