Closed jeremiahlukus closed 5 months ago
Also to enable lambda insights locally i ran
export URL=$(aws lambda get-layer-version-by-arn --arn arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:19 --query Content.Location --output text --region us-east-1)
curl -o LambdaInsightsExtension-Arm64.zip $URL
Then in my Dockerfile after coping the code over
COPY LambdaInsightsExtension-Arm64.zip /opt
RUN unzip /opt/LambdaInsightsExtension-Arm64.zip -d /opt/
Then in your lambda add
- CloudWatchLambdaInsightsExecutionRolePolicy
The way to do this in the aws docs does not work for arm64
Lastly since i wanted to use arm64 I was unable to deploy using github actions. I am using code build instead
data "local_file" "buildspec_local" {
filename = "${path.module}/buildspec.yml"
}
resource "aws_codebuild_project" "name" {
badge_enabled = false
build_timeout = 60
concurrent_build_limit = 5
description = null
encryption_key = "arn:aws:kms:us-east-1:533085732793:alias/aws/s3"
name = "APPNAME-remote"
project_visibility = "PRIVATE"
queued_timeout = 480
resource_access_role = null
service_role = "arn:aws:iam::533085732793:role/code-build"
source_version = "main"
tags = {}
tags_all = {}
artifacts {
artifact_identifier = null
bucket_owner_access = null
encryption_disabled = false
location = null
name = null
namespace_type = null
override_artifact_name = false
packaging = null
path = null
type = "NO_ARTIFACTS"
}
cache {
location = null
modes = ["LOCAL_DOCKER_LAYER_CACHE", "LOCAL_CUSTOM_CACHE"]
type = "LOCAL"
}
environment {
certificate = null
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/amazonlinux2-aarch64-standard:3.0"
image_pull_credentials_type = "CODEBUILD"
privileged_mode = true
type = "ARM_CONTAINER"
}
logs_config {
cloudwatch_logs {
group_name = null
status = "ENABLED"
stream_name = null
}
s3_logs {
bucket_owner_access = null
encryption_disabled = false
location = null
status = "DISABLED"
}
}
source {
type = "GITHUB"
location = "https://github.com/USERNAME/REPO.git"
git_clone_depth = 1
buildspec = data.local_file.buildspec_local.content
git_submodules_config {
fetch_submodules = true
}
}
}
buildspec is simple and it shouldn't get ran because im overriding it in my github action
version: 0.2
phases:
install:
runtime-versions:
ruby: 3.2
build:
commands:
- echo "== DEPLOY =="
- RAILS_ENV=review bin/deploy
your ruby version needs to be 3.2.2 in order to use the AWS runtime.
Now i created a github workflow so i dont have to go to codebuild and see the progress of my build
- name: Run CodeBuild
uses: aws-actions/aws-codebuild-run-build@v1
with:
project-name: ${{ inputs.PROJECT_NAME }}
disable-source-override: false
source-version-override: ${{ github.sha }}
buildspec-override: |
version: 0.2
phases:
install:
runtime-versions:
ruby: 3.2
build:
commands:
- echo "== DOCKER LOGIN =="
- docker login -u ${{ inputs.DOCKER_USER }} -p ${{ inputs.DOCKER_PASS }}
- echo "== DEPLOY =="
- cd rails_api
- RAILS_ENV=${{ inputs.ENVIRONMENT}} bin/deploy
Im using the same code build project to deploy all envs i just pass in the rails env and it deploys that env.
It took me awhile to figure out how to get the function url in the cloudfront distro.
I want to share my config which does a few basic things
To me this is basic config i want for every app +/- the queue for jobs.
I also use a prewarming function because it seems cheaper than Provisioned Concurrency. According to https://calculator.aws/#/createCalculator/Lambda
With that being said here is the template.yml and I hope I can save someone searching for cloudfront config a few hours getting the function url