Skip to content

Create lambdas with terraform #224

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

Merged
merged 32 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2a456b7
create lambda with aws
devksingh4 Jul 27, 2025
54a2afb
updates
devksingh4 Jul 27, 2025
dcaef05
update arn
devksingh4 Jul 27, 2025
e5288f6
dont do sam stuff rn
devksingh4 Jul 27, 2025
702758b
fix
devksingh4 Jul 27, 2025
991869b
fix role name
devksingh4 Jul 27, 2025
12297d7
update
devksingh4 Jul 27, 2025
c8679cf
update
devksingh4 Jul 27, 2025
6318b88
fix
devksingh4 Jul 27, 2025
aaf9b49
Auto-update feature branch with changes from the main branch
github-actions[bot] Jul 27, 2025
3986322
update
devksingh4 Jul 27, 2025
13d1a59
fix
devksingh4 Jul 27, 2025
3780444
fix param
devksingh4 Jul 27, 2025
0096fef
update
devksingh4 Jul 27, 2025
d08df9a
update
devksingh4 Jul 27, 2025
0c21cc6
update config
devksingh4 Jul 27, 2025
c1db1ee
cleanup
devksingh4 Jul 27, 2025
6027c9e
fix meta files
devksingh4 Jul 27, 2025
45fd0a6
fix role name
devksingh4 Jul 27, 2025
ac2f4f7
update provisioner
devksingh4 Jul 27, 2025
2a028a6
update terraform lockfile
devksingh4 Jul 27, 2025
c14193d
update environment
devksingh4 Jul 27, 2025
7972612
update build command
devksingh4 Jul 27, 2025
5c20848
fix
devksingh4 Jul 27, 2025
16116f4
lock down iam roles
devksingh4 Jul 27, 2025
a71099d
fix SIDs
devksingh4 Jul 27, 2025
eda54ff
fix IAM rule
devksingh4 Jul 27, 2025
83de4b5
allow SQS send message permission
devksingh4 Jul 27, 2025
c8bb228
fix sqs send policy
devksingh4 Jul 27, 2025
e3490b5
update IAM part 3
devksingh4 Jul 27, 2025
4990621
fix role attachment
devksingh4 Jul 27, 2025
1a7aa42
fix name
devksingh4 Jul 27, 2025
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
8 changes: 1 addition & 7 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,7 @@ jobs:
- uses: actions/checkout@v4
env:
HUSKY: "0"
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Download Build files
uses: actions/download-artifact@v4
with:
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/deploy-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,6 @@ jobs:
with:
name: build

- uses: aws-actions/setup-sam@v2
with:
use-installer: true

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- uses: aws-actions/configure-aws-credentials@v4
with:
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/manual-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
- build
environment: "AWS PROD"
steps:
- name: Set up Node for testing
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22.x
Expand All @@ -110,13 +110,7 @@ jobs:
- uses: actions/checkout@v4
env:
HUSKY: "0"
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Download Build files
uses: actions/download-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Cloud provider files
paths:
- '.github/'
- 'cloudformation/'
- 'terraform/'
teams:
- "officers"
- "infra-chairs"
Expand Down
87 changes: 15 additions & 72 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
run_env = ParameterKey=RunEnvironment,ParameterValue
set_application_prefix = ParameterKey=ApplicationPrefix,ParameterValue
set_application_name = ParameterKey=ApplicationFriendlyName,ParameterValue

prod_aws_account = 298118738376
dev_aws_account = 427040638965
current_aws_account := $(shell aws sts get-caller-identity --query Account --output text)

src_directory_root = src/
dist_ui_directory_root = dist_ui/
integration_test_directory_root = tests/live_integration/

# CHANGE ME (as needed)
application_key=infra-core-api
application_name="InfraCoreApi"
techlead="[email protected]"
region="us-east-1"

# DO NOT CHANGE
common_params = --no-confirm-changeset \
--no-fail-on-empty-changeset \
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND \
--region $(region) \
--stack-name $(application_key) \
--tags "project=$(application_key)" "techlead=$(techlead)" \
--s3-prefix $(application_key) \
--resolve-s3

s3_bucket_prefix = "$(current_aws_account)-$(region)-$(application_key)"
ui_s3_bucket = "$(s3_bucket_prefix)-ui"
docs_s3_bucket = "$(s3_bucket_prefix)-docs"


npm_install_params = --omit=dev --target_arch=arm64 --target_platform=linux --target_libc=glibc --cpu arm64 --os linux --arch=arm64
GIT_HASH := $(shell git rev-parse --short HEAD)
ORIGIN_SECRET := $(shell openssl rand -hex 32)

.PHONY: clean

Expand Down Expand Up @@ -60,80 +34,49 @@ clean:
build_swagger:
cd src/api && npx tsx --experimental-loader=./mockLoader.mjs createSwagger.ts && cd ../..

build: src/ cloudformation/
build: src/
yarn -D
yarn build
make build_swagger
cp -r src/api/resources/ dist/api/resources
rm -rf dist/lambda/sqs
sam build --template-file cloudformation/main.yml --use-container --parallel
mkdir -p .aws-sam/build/AppApiLambdaFunction/node_modules/aws-crt/
cp -r node_modules/aws-crt/dist .aws-sam/build/AppApiLambdaFunction/node_modules/aws-crt
## IF WE EVER CHANGE THE LAMBDA ARCH, BE SURE TO CHANGE THESE ##
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/aws-crt/dist/bin/darwin*
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/aws-crt/dist/bin/linux-x64*
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/aws-crt/dist/bin/linux-arm64-musl
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/argon2/prebuilds/darwin*
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/argon2/prebuilds/freebsd*
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/argon2/prebuilds/linux-arm
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/argon2/prebuilds/linux-x64*
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/argon2/prebuilds/win32-x64*
rm -rf .aws-sam/build/AppApiLambdaFunction/node_modules/argon2/prebuilds/linux-arm64/argon2.armv8.musl.node
docker run --rm -v "$(shell pwd)/dist/lambda":/var/task public.ecr.aws/sam/build-nodejs22.x:latest \
sh -c "npm install $(npm_install_params) && \
rm -rf node_modules/aws-crt/dist/bin/{darwin*,linux-x64*,linux-arm64-musl} && \
rm -rf node_modules/argon2/prebuilds/{darwin*,freebsd*,linux-arm,linux-x64*,win32-x64*} && \
rm -rf node_modules/argon2/prebuilds/linux-arm64/argon2.armv8.musl.node"

docker run --rm -v "$(shell pwd)/dist/sqsConsumer":/var/task public.ecr.aws/sam/build-nodejs22.x:latest \
sh -c "npm install $(npm_install_params) && \
rm -rf node_modules/aws-crt/dist/bin/{darwin*,linux-x64*,linux-arm64-musl} && \
rm -rf node_modules/argon2/prebuilds/{darwin*,freebsd*,linux-arm,linux-x64*,win32-x64*} && \
rm -rf node_modules/argon2/prebuilds/linux-arm64/argon2.armv8.musl.node"

local:
VITE_BUILD_HASH=$(GIT_HASH) yarn run dev


postdeploy:
@echo "Syncing S3 UI bucket..."
aws s3 sync $(dist_ui_directory_root) s3://$(ui_s3_bucket)/ --delete
make invalidate_cloudfront

deploy_prod: check_account_prod
@echo "Deploying CloudFormation stack..."
@sam deploy $(common_params) --parameter-overrides $(run_env)=prod $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)" S3BucketPrefix="$(s3_bucket_prefix)" CloudfrontOriginSecret="$(ORIGIN_SECRET)"
@echo "Deploying Terraform..."
$(eval MAIN_DISTRIBUTION_ID := $(shell aws cloudformation describe-stacks --stack-name $(application_key) --query "Stacks[0].Outputs[?OutputKey=='CloudfrontDistributionId'].OutputValue" --output text))
terraform -chdir=terraform/envs/prod init -lockfile=readonly
terraform -chdir=terraform/envs/prod apply -auto-approve -var main_cloudfront_distribution_id="$(MAIN_DISTRIBUTION_ID)"
make postdeploy
terraform -chdir=terraform/envs/prod apply -auto-approve

deploy_dev: check_account_dev
@echo "Deploying CloudFormation stack..."
@sam deploy $(common_params) --parameter-overrides $(run_env)=dev $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)" S3BucketPrefix="$(s3_bucket_prefix)" CloudfrontOriginSecret="$(ORIGIN_SECRET)"
@echo "Deploying Terraform..."
$(eval MAIN_DISTRIBUTION_ID := $(shell aws cloudformation describe-stacks --stack-name $(application_key) --query "Stacks[0].Outputs[?OutputKey=='CloudfrontDistributionId'].OutputValue" --output text))
terraform -chdir=terraform/envs/qa init -lockfile=readonly
terraform -chdir=terraform/envs/qa apply -auto-approve -var main_cloudfront_distribution_id="$(MAIN_DISTRIBUTION_ID)"
make postdeploy

invalidate_cloudfront:
@echo "Creating CloudFront invalidation..."
$(eval DISTRIBUTION_ID := $(shell aws cloudformation describe-stacks --stack-name $(application_key) --query "Stacks[0].Outputs[?OutputKey=='CloudfrontDistributionId'].OutputValue" --output text))
$(eval DISTRIBUTION_ID_2 := $(shell aws cloudformation describe-stacks --stack-name $(application_key) --query "Stacks[0].Outputs[?OutputKey=='CloudfrontIcalDistributionId'].OutputValue" --output text))
$(eval INVALIDATION_ID := $(shell aws cloudfront create-invalidation --distribution-id $(DISTRIBUTION_ID) --paths "/*" --query 'Invalidation.Id' --output text --no-cli-page))
$(eval INVALIDATION_ID_2 := $(shell aws cloudfront create-invalidation --distribution-id $(DISTRIBUTION_ID_2) --paths "/*" --query 'Invalidation.Id' --output text --no-cli-page))
@echo "Triggered invalidation jobs $(INVALIDATION_ID) and $(INVALIDATION_ID_2)..."
@echo "Waiting on job $(INVALIDATION_ID)..."
aws cloudfront wait invalidation-completed --distribution-id $(DISTRIBUTION_ID) --id $(INVALIDATION_ID)
@echo "Waiting on job $(INVALIDATION_ID_2)..."
aws cloudfront wait invalidation-completed --distribution-id $(DISTRIBUTION_ID_2) --id $(INVALIDATION_ID_2)
@echo "CloudFront invalidation completed!"
terraform -chdir=terraform/envs/qa apply -auto-approve

init_terraform:
terraform -chdir=terraform/envs/qa init
terraform -chdir=terraform/envs/prod init

install:
yarn -D
pip install cfn-lint

test_live_integration: install
yarn test:live

test_unit: install
yarn lint
cfn-lint cloudformation/**/*
terraform -chdir=terraform/envs/qa init -reconfigure -backend=false -upgrade
terraform -chdir=terraform/envs/qa fmt -check
terraform -chdir=terraform/envs/qa validate
Expand Down
Loading
Loading