Skip to content

Commit

Permalink
lambda and dynamodb get and post working on aws ca-central-1
Browse files Browse the repository at this point in the history
  • Loading branch information
socraticDevBlog committed Dec 23, 2023
1 parent 509e8c7 commit 24d71d4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,7 @@ cython_debug/
.aws-sam
src.zip

backend.tf
backend.tf
terraform-provider*
.terraform*
*.zip
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ To run tests, run the following command
pipenv run test -v
```

## deploying

We chose Terraform to deploy this app to AWS

### layers (installed python depenencies)
Make sure to package your dependancies in a zip file to add it as a layer to
our lambda -> https://spak.no/blog/article/63f47f130faeadeeeb968ae9

in a nutshell (you need to adapt to your local machine)

```bash
mkdir python
cp -r $HOME/.local/share/virtualenvs/pastebin-<SOME ID>/lib python/
zip -r layer.zip /python
mv layer.zip git/pastebin/terraform
```

## Roadmap

- [x] implement a DynamoDB CRUD client
Expand Down
7 changes: 7 additions & 0 deletions terraform/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
backend "s3" {
bucket = ""
key = "tfstate-20231222"
region = "ca-central-1"
}
}
19 changes: 13 additions & 6 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ terraform {
}

provider "aws" {
profile = "default"
region = "ca-central-1"
access_key = "fill me"
secret_key = "fille me too"
profile = "default"
region = "ca-central-1"
}

resource "random_string" "random" {
Expand Down Expand Up @@ -70,6 +68,13 @@ resource "aws_s3_bucket_acl" "private_bucket" {
acl = "private"
}

resource "aws_lambda_layer_version" "python-layer" {
filename = "layer.zip"
layer_name = "python-layer"
source_code_hash = filebase64sha256("layer.zip")
compatible_runtimes = ["python3.9"]
}

data "archive_file" "lambda_zip" {
type = "zip"

Expand Down Expand Up @@ -103,11 +108,13 @@ resource "aws_lambda_function" "apigw_lambda_ddb" {

environment {
variables = {
DDB_TABLE = var.dynamodb_table
DDB_TABLE = var.dynamodb_table,
AWS_SAM_LOCAL = "false",
DEVENV = "false"
}
}
layers = [aws_lambda_layer_version.python-layer.arn]
depends_on = [aws_cloudwatch_log_group.lambda_logs]

}

resource "aws_cloudwatch_log_group" "lambda_logs" {
Expand Down

0 comments on commit 24d71d4

Please sign in to comment.