Skip to content

Commit

Permalink
Add Lambda function and configure deployment
Browse files Browse the repository at this point in the history
This commit adds a new Lambda function with its associated Dockerfile, package.json and deployment configuration files. It also includes the necessary updates to the GitHub Actions workflow and the Terraform configuration for automatic deployment of the function. Additionally, the .gitignore file has been updated to ignore the newly added directories and files related to the Lambda function installation and execution.
  • Loading branch information
timam committed May 16, 2024
1 parent f669d3b commit 1ae58a7
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
name: build docker image
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push image to Amazon ECR
run: |
cd demo/lambda/src
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA -f Dockerfile .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$GITHUB_SHA
133 changes: 132 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,135 @@
terraform.tfstate.d
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
terraform.tfstate.backup

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
3 changes: 3 additions & 0 deletions demo/lambda/deployment/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


docker buildx build --platform linux/amd64,linux/arm64 -t 590184123335.dkr.ecr.ap-southeast-1.amazonaws.com/demo-awscd-2024:init . --push
7 changes: 7 additions & 0 deletions demo/lambda/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM public.ecr.aws/lambda/nodejs:14

COPY app.js package.json ./

RUN npm install

CMD [ "app.handler" ]
7 changes: 7 additions & 0 deletions demo/lambda/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports.handler = async (event) => {
const response = {
statusCode: 200
body: JSON.stringify('Hello from Lambda!')
};
return response;
};
12 changes: 12 additions & 0 deletions demo/lambda/src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "src",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
8 changes: 8 additions & 0 deletions iac/ecr.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "aws_ecr_repository" "awscd" {
name = "demo-awscd-2024"
image_tag_mutability = "MUTABLE"

image_scanning_configuration {
scan_on_push = true
}
}

0 comments on commit 1ae58a7

Please sign in to comment.