Skip to content

Commit 2c56b11

Browse files
author
Adetokunbo Ige
committed
chore: update policy
Signed-off-by: Adetokunbo Ige <[email protected]>
1 parent 182373b commit 2c56b11

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

todo-app/Pulumi.dev.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
config:
22
todo-app:docker_image: 289940214902.dkr.ecr.us-east-1.amazonaws.com/todo_pulumi_docker_aws_lambda_api_gateway:3f8cc06
3-
todo-app:environment: dev
3+
todo-app:environment: dev
4+
todo-app:region: us-east-1

todo-app/__main__.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
docker_image = config.get("docker_image")
1212
environment = config.get("environment")
13+
region = config.get("region")
14+
15+
aws.config.region = region
1316

1417
# First, create the DynamoDB table
1518
dynamodb_table = aws.dynamodb.Table(
@@ -36,7 +39,8 @@
3639

3740
# Create Lambda execution role
3841
lambda_role = aws.iam.Role(
39-
"lambdaExecutionRole",
42+
f"lambdaExecutionRole-{environment}",
43+
name=f"lambdaExecutionRole-{environment}",
4044
assume_role_policy=json.dumps({
4145
"Version": "2012-10-17",
4246
"Statement": [{
@@ -52,7 +56,8 @@
5256

5357
# Create inline policy for the role
5458
dynamodb_policy = aws.iam.RolePolicy(
55-
"lambdaRolePolicy",
59+
f"lambdaRolePolicy-{environment}",
60+
name=f"lambdaRolePolicy-{environment}",
5661
role=lambda_role.id,
5762
policy=pulumi.Output.json_dumps({
5863
"Version": "2012-10-17",
@@ -86,8 +91,8 @@
8691
)
8792

8893
# Create a Lambda function using the Docker image
89-
lambda_function = aws.lambda_.Function("my-serverless-function",
90-
name="my-serverless-function",
94+
lambda_function = aws.lambda_.Function(f"my-serverless-function-{environment}",
95+
name=f"my-serverless-function-{environment}",
9196
role=lambda_role.arn, # Make sure you have the correct IAM role
9297
package_type="Image", # Specify that this is a Docker image
9398
image_uri=docker_image, # Use the image name from the previous step
@@ -96,40 +101,40 @@
96101
)
97102

98103
# Create an API Gateway REST API
99-
api = aws.apigateway.RestApi("my-api",
104+
api = aws.apigateway.RestApi(f"my-api-{environment}",
100105
description="My serverless API")
101106

102107
# Create a catch-all resource for the API
103-
proxy_resource = aws.apigateway.Resource("proxy-resource",
108+
proxy_resource = aws.apigateway.Resource(f"proxy-resource-{environment}",
104109
rest_api=api.id,
105110
parent_id=api.root_resource_id,
106111
path_part="{proxy+}")
107112

108113
# Create a method for the proxy resource that allows any method
109-
method = aws.apigateway.Method("proxy-method",
114+
method = aws.apigateway.Method(f"proxy-method-{environment}",
110115
rest_api=api.id,
111116
resource_id=proxy_resource.id,
112117
http_method="ANY",
113118
authorization="NONE")
114119

115120
# Integration of Lambda with API Gateway using AWS_PROXY
116-
integration = aws.apigateway.Integration("proxy-integration",
121+
integration = aws.apigateway.Integration(f"proxy-integration-{environment}",
117122
rest_api=api.id,
118123
resource_id=proxy_resource.id,
119124
http_method=method.http_method,
120125
integration_http_method="POST",
121126
type="AWS_PROXY",
122127
uri=lambda_function.invoke_arn) # Ensure lambda_function is defined
123128

124-
lambda_permission = aws.lambda_.Permission("api-gateway-lambda-permission",
129+
lambda_permission = aws.lambda_.Permission(f"api-gateway-lambda-permission-{environment}",
125130
action="lambda:InvokeFunction",
126131
function=lambda_function.name,
127132
principal="apigateway.amazonaws.com",
128133
source_arn=pulumi.Output.concat(api.execution_arn, "/*/*")
129134
)
130135

131136
# Deployment of the API, explicitly depends on method and integration to avoid timing issues
132-
deployment = aws.apigateway.Deployment("api-deployment",
137+
deployment = aws.apigateway.Deployment(f"api-deployment-{environment}",
133138
rest_api=api.id,
134139
stage_name="dev",
135140
opts=pulumi.ResourceOptions(

0 commit comments

Comments
 (0)