Skip to content

Commit

Permalink
MLPAB-1518 - enable lambda insights for image lambda (#810)
Browse files Browse the repository at this point in the history
* enable lambda insights for image lambda

* attach lambda insights policy

* detect changes to dockerfiles
  • Loading branch information
andrewpearce-digital authored Nov 2, 2023
1 parent abb6cf7 commit 4298ebf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/detect_changes_to_app_job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ jobs:
echo "Build status of ${{github.event.before}}: $BEFORE_STATUS"
if [[ "$BEFORE_STATUS" == "success" ]]; then
echo "Checking against ${{github.event.before}}"
(git diff --quiet ${{github.event.before}} ${{github.event.after}} -- cmd internal lang web lambda Dockerfile package.json yarn.lock go.mod && \
(git diff --quiet ${{github.event.before}} ${{github.event.after}} -- cmd internal lang web lambda docker/event-received docker/mlpa package.json yarn.lock go.mod && \
echo "changes=${{ false }}" || \
echo "changes=${{ true }}") | tee -a "${GITHUB_OUTPUT}"
else
echo "Checking against origin/main"
(git diff --quiet HEAD origin/main -- cmd internal lang web lambda Dockerfile package.json yarn.lock go.mod && \
(git diff --quiet HEAD origin/main -- cmd internal lang web lambda docker/event-received docker/mlpa package.json yarn.lock go.mod && \
echo "changes=${{ false }}" || \
echo "changes=${{ true }}") | tee -a "${GITHUB_OUTPUT}"
fi
Expand Down
8 changes: 8 additions & 0 deletions docker/event-received/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags lambda.norpc -o event-r

FROM public.ecr.aws/lambda/provided:al2 AS dev

WORKDIR /app

COPY --from=build /app/event-received ./event-received
COPY lang ./lang
COPY docker/event-received/aws-lambda-rie ./aws-lambda-rie
Expand All @@ -20,6 +22,12 @@ ENTRYPOINT ["./event-received"]

FROM public.ecr.aws/lambda/provided:al2 AS production

WORKDIR /app

RUN curl -O https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension.rpm && \
rpm -U lambda-insights-extension.rpm && \
rm -f lambda-insights-extension.rpm ;

COPY --from=build /app/event-received ./event-received
COPY lang ./lang

Expand Down
6 changes: 6 additions & 0 deletions terraform/environment/region/modules/event_received/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ resource "aws_iam_role_policy" "event_received" {
provider = aws.region
}

resource "aws_iam_role_policy_attachment" "cloudwatch_lambda_insights" {
role = module.event_received.lambda_role.id
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
provider = aws.region
}

data "aws_kms_alias" "dynamodb_encryption_key" {
name = "alias/${data.aws_default_tags.current.tags.application}_dynamodb_encryption"
provider = aws.region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ data "aws_iam_policy_document" "scheduler_invoke_lambda" {
}
provider = aws.region
}

resource "aws_iam_role_policy_attachment" "cloudwatch_lambda_insights" {
role = module.s3_create_batch_replication_jobs.lambda_role.id
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
provider = aws.region
}

0 comments on commit 4298ebf

Please sign in to comment.