Skip to content

Commit 43e143e

Browse files
author
Adetokunbo Ige
committed
chore: update the pulumi stack name
Signed-off-by: Adetokunbo Ige <[email protected]>
1 parent a0caf11 commit 43e143e

File tree

7 files changed

+70
-18
lines changed

7 files changed

+70
-18
lines changed

.github/workflows/pulumi-deploy.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ on:
1010
jobs:
1111
pulumi-deploy:
1212
runs-on: ubuntu-latest
13-
env:
14-
AWS_REGION: ${{ secrets.AWS_REGION }}
1513

1614
permissions:
1715
id-token: write
@@ -36,16 +34,25 @@ jobs:
3634
run: |
3735
pip install -r requirements.txt
3836
39-
- uses: pulumi/actions@v3
40-
with:
41-
command: preview
42-
stack-name: dev
37+
- name: Configure Pulumi
38+
working-directory: todo-app
39+
run: |
40+
pulumi stack select ExitoLab/todo-app/dev --non-interactive || pulumi stack init ExitoLab/todo-app/dev
4341
env:
4442
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
4543

46-
- uses: pulumi/actions@v3
47-
with:
48-
command: up
49-
stack-name: dev
44+
- name: Pulumi Preview
45+
working-directory: todo-app
46+
run: |
47+
pulumi stack select ExitoLab/todo-app/dev
48+
pulumi preview
49+
env:
50+
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
51+
52+
- name: Pulumi Up
53+
working-directory: todo-app
54+
run: |
55+
pulumi stack select ExitoLab/todo-app/dev
56+
pulumi up --yes
5057
env:
5158
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Building and Deploying a Serverless Todo App on AWS with Docker, Lambda, API Gateway, and GitHub Actions using Pulumi in Python
1+
# Building and Deploying a Serverless Todo App on AWS using Pulumi in Python
22

33
## Overview
44

todo-app/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
*.pyc
22
venv/
3-

todo-app/Pulumi.dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
config:
2-
todo-app:location: eastus
2+
todo-app:docker_image: 289940214902.dkr.ecr.us-east-1.amazonaws.com/todo-app:v1.1

todo-app/Pulumi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ config:
99
pulumi:tags:
1010
value:
1111
pulumi:template: aws-python
12+

todo-app/__main__.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
from pulumi_docker import Image, DockerBuild
44
import pulumi_docker as docker
55

6-
# Step 1: Create an ECR repository
7-
docker_image = "289940214902.dkr.ecr.us-east-1.amazonaws.com/todo-app:v1.1"
6+
from pulumi import Config
7+
8+
# Create a config object to access configuration values
9+
config = pulumi.Config()
10+
11+
docker_image = config.get("docker_image")
812

913
# Create an IAM Role for the Lambda function
1014
lambda_role = aws.iam.Role("lambdaExecutionRole",
@@ -29,6 +33,47 @@
2933
policy_arn="arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
3034
)
3135

36+
# Define an IAM policy that allows DynamoDB scan action
37+
dynamodb_scan_policy = aws.iam.Policy("dynamodb_policy",
38+
policy={
39+
"Version": "2012-10-17",
40+
"Statement": [
41+
{
42+
"Effect": "Allow",
43+
"Action": "dynamodb:Scan",
44+
"Resource": "arn:aws:dynamodb:us-east-1:289940214902:table/todo"
45+
}
46+
]
47+
}
48+
)
49+
50+
# Attach the policy to the Lambda execution role
51+
role_policy_attachment = aws.iam.RolePolicyAttachment("lambda-role-policy-attachment",
52+
role=lambda_role.name,
53+
policy_arn=dynamodb_policy.arn
54+
)
55+
56+
# Define a DynamoDB table
57+
dynamodb_table = aws.dynamodb.Table("todo",
58+
hash_key="id", # Partition key
59+
range_key="timestamp", # Sort key
60+
attributes=[
61+
aws.dynamodb.TableAttributeArgs(
62+
name="id",
63+
type="S" # S for string
64+
),
65+
aws.dynamodb.TableAttributeArgs(
66+
name="timestamp",
67+
type="N" # N for number
68+
),
69+
],
70+
billing_mode="PAY_PER_REQUEST", # Use on-demand mode (no provisioned throughput)
71+
tags={
72+
"Environment": "dev",
73+
"Created_By": "Pulumi"
74+
}
75+
)
76+
3277
# Create a Lambda function using the Docker image
3378
lambda_function = aws.lambda_.Function("my-serverless-function",
3479
name="my-serverless-function",
@@ -65,15 +110,13 @@
65110
type="AWS_PROXY",
66111
uri=lambda_function.invoke_arn) # Ensure lambda_function is defined
67112

68-
69113
lambda_permission = aws.lambda_.Permission("api-gateway-lambda-permission",
70114
action="lambda:InvokeFunction",
71115
function=lambda_function.name,
72116
principal="apigateway.amazonaws.com",
73117
source_arn=pulumi.Output.concat(api.execution_arn, "/*/*")
74118
)
75119

76-
77120
# Deployment of the API, explicitly depends on method and integration to avoid timing issues
78121
deployment = aws.apigateway.Deployment("api-deployment",
79122
rest_api=api.id,

todo-app/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
pulumi>=3.0.0,<4.0.0
22
pulumi-aws>=6.0.2,<7.0.0
33
pulumi_docker==3.4.0
4-
setuptools
4+
setuptools
5+
6+

0 commit comments

Comments
 (0)