|
10 | 10 |
|
11 | 11 | docker_image = config.get("docker_image")
|
12 | 12 | environment = config.get("environment")
|
| 13 | +region = config.get("region") |
| 14 | + |
| 15 | +aws.config.region = region |
13 | 16 |
|
14 | 17 | # First, create the DynamoDB table
|
15 | 18 | dynamodb_table = aws.dynamodb.Table(
|
|
36 | 39 |
|
37 | 40 | # Create Lambda execution role
|
38 | 41 | lambda_role = aws.iam.Role(
|
39 |
| - "lambdaExecutionRole", |
| 42 | + f"lambdaExecutionRole-{environment}", |
| 43 | + name=f"lambdaExecutionRole-{environment}", |
40 | 44 | assume_role_policy=json.dumps({
|
41 | 45 | "Version": "2012-10-17",
|
42 | 46 | "Statement": [{
|
|
52 | 56 |
|
53 | 57 | # Create inline policy for the role
|
54 | 58 | dynamodb_policy = aws.iam.RolePolicy(
|
55 |
| - "lambdaRolePolicy", |
| 59 | + f"lambdaRolePolicy-{environment}", |
| 60 | + name=f"lambdaRolePolicy-{environment}", |
56 | 61 | role=lambda_role.id,
|
57 | 62 | policy=pulumi.Output.json_dumps({
|
58 | 63 | "Version": "2012-10-17",
|
|
86 | 91 | )
|
87 | 92 |
|
88 | 93 | # 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}", |
91 | 96 | role=lambda_role.arn, # Make sure you have the correct IAM role
|
92 | 97 | package_type="Image", # Specify that this is a Docker image
|
93 | 98 | image_uri=docker_image, # Use the image name from the previous step
|
|
96 | 101 | )
|
97 | 102 |
|
98 | 103 | # Create an API Gateway REST API
|
99 |
| -api = aws.apigateway.RestApi("my-api", |
| 104 | +api = aws.apigateway.RestApi(f"my-api-{environment}", |
100 | 105 | description="My serverless API")
|
101 | 106 |
|
102 | 107 | # 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}", |
104 | 109 | rest_api=api.id,
|
105 | 110 | parent_id=api.root_resource_id,
|
106 | 111 | path_part="{proxy+}")
|
107 | 112 |
|
108 | 113 | # 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}", |
110 | 115 | rest_api=api.id,
|
111 | 116 | resource_id=proxy_resource.id,
|
112 | 117 | http_method="ANY",
|
113 | 118 | authorization="NONE")
|
114 | 119 |
|
115 | 120 | # 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}", |
117 | 122 | rest_api=api.id,
|
118 | 123 | resource_id=proxy_resource.id,
|
119 | 124 | http_method=method.http_method,
|
120 | 125 | integration_http_method="POST",
|
121 | 126 | type="AWS_PROXY",
|
122 | 127 | uri=lambda_function.invoke_arn) # Ensure lambda_function is defined
|
123 | 128 |
|
124 |
| -lambda_permission = aws.lambda_.Permission("api-gateway-lambda-permission", |
| 129 | +lambda_permission = aws.lambda_.Permission(f"api-gateway-lambda-permission-{environment}", |
125 | 130 | action="lambda:InvokeFunction",
|
126 | 131 | function=lambda_function.name,
|
127 | 132 | principal="apigateway.amazonaws.com",
|
128 | 133 | source_arn=pulumi.Output.concat(api.execution_arn, "/*/*")
|
129 | 134 | )
|
130 | 135 |
|
131 | 136 | # 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}", |
133 | 138 | rest_api=api.id,
|
134 | 139 | stage_name="dev",
|
135 | 140 | opts=pulumi.ResourceOptions(
|
|
0 commit comments