@aws/nx-plugin 0.45.1 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +3669 -0
- package/src/py/fast-api/generator.js +57 -50
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/schema.d.ts +1 -0
- package/src/py/fast-api/schema.json +8 -0
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +590 -0
- package/src/py/mcp-server/generator.js +4 -18
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/mcp-server/schema.d.ts +1 -0
- package/src/py/mcp-server/schema.json +8 -0
- package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +590 -0
- package/src/py/strands-agent/generator.js +4 -18
- package/src/py/strands-agent/generator.js.map +1 -1
- package/src/py/strands-agent/schema.d.ts +1 -0
- package/src/py/strands-agent/schema.json +8 -0
- package/src/terraform/project/generator.js +23 -7
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +3669 -0
- package/src/trpc/backend/generator.js +6 -17
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +1 -0
- package/src/trpc/backend/schema.json +8 -0
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +590 -0
- package/src/ts/mcp-server/generator.js +4 -18
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/mcp-server/schema.d.ts +1 -0
- package/src/ts/mcp-server/schema.json +8 -0
- package/src/ts/nx-plugin/generator.js +1 -0
- package/src/ts/nx-plugin/generator.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +11 -5
- package/src/utils/agent-core-constructs/agent-core-constructs.js +51 -10
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +46 -0
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +536 -0
- package/src/utils/api-constructs/api-constructs.d.ts +4 -4
- package/src/utils/api-constructs/api-constructs.js +45 -5
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +382 -0
- package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +508 -0
- package/src/utils/api-constructs/files/terraform/core/api/http/http-api/http-api.tf.template +250 -0
- package/src/utils/api-constructs/files/terraform/core/api/rest/rest-api/rest-api.tf.template +150 -0
- package/src/utils/files/terraform/src/metrics/metrics.tf.template +3 -2
- package/src/utils/py.d.ts +5 -0
- package/src/utils/py.js +9 -1
- package/src/utils/py.js.map +1 -1
- package/src/utils/shared-constructs-constants.d.ts +2 -0
- package/src/utils/shared-constructs-constants.js +3 -1
- package/src/utils/shared-constructs-constants.js.map +1 -1
- package/src/utils/shared-constructs.js +2 -2
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/versions.d.ts +3 -1
- package/src/utils/versions.js +2 -0
- package/src/utils/versions.js.map +1 -1
- /package/src/utils/agent-core-constructs/files/{app → cdk/app}/agent-core/__nameKebabCase__/Dockerfile.template +0 -0
- /package/src/utils/agent-core-constructs/files/{app → cdk/app}/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +0 -0
- /package/src/utils/agent-core-constructs/files/{core → cdk/core}/agent-core/runtime.ts.template +0 -0
- /package/src/utils/api-constructs/files/{app → cdk/app}/apis/http/__apiNameKebabCase__.ts.template +0 -0
- /package/src/utils/api-constructs/files/{app → cdk/app}/apis/rest/__apiNameKebabCase__.ts.template +0 -0
- /package/src/utils/api-constructs/files/{core → cdk/core}/api/http/http-api.ts.template +0 -0
- /package/src/utils/api-constructs/files/{core → cdk/core}/api/rest/rest-api.ts.template +0 -0
- /package/src/utils/api-constructs/files/{core → cdk/core}/api/trpc/trpc-utils.ts.template +0 -0
- /package/src/utils/api-constructs/files/{core → cdk/core}/api/utils/utils.ts.template +0 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
terraform {
|
|
2
|
+
required_version = ">= 1.0"
|
|
3
|
+
|
|
4
|
+
required_providers {
|
|
5
|
+
aws = {
|
|
6
|
+
source = "hashicorp/aws"
|
|
7
|
+
version = "~> 6.0"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
<%_ if (auth === 'Cognito') { _%>
|
|
13
|
+
# Authentication Configuration
|
|
14
|
+
variable "user_pool_id" {
|
|
15
|
+
description = "Cognito User Pool ID for authentication"
|
|
16
|
+
type = string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
variable "user_pool_client_ids" {
|
|
20
|
+
description = "List of Cognito User Pool Client IDs"
|
|
21
|
+
type = list(string)
|
|
22
|
+
}
|
|
23
|
+
<%_ } _%>
|
|
24
|
+
|
|
25
|
+
variable "env" {
|
|
26
|
+
description = "Environment variables for the Lambda function"
|
|
27
|
+
type = map(string)
|
|
28
|
+
default = {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
variable "additional_iam_policy_statements" {
|
|
32
|
+
description = "Additional IAM policy statements for the Lambda function"
|
|
33
|
+
type = list(object({
|
|
34
|
+
Effect = string
|
|
35
|
+
Action = list(string)
|
|
36
|
+
Resource = list(string)
|
|
37
|
+
}))
|
|
38
|
+
default = []
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# CORS Configuration (passed to core module)
|
|
42
|
+
|
|
43
|
+
variable "cors_allow_headers" {
|
|
44
|
+
description = "List of allowed headers for CORS"
|
|
45
|
+
type = list(string)
|
|
46
|
+
default = ["authorization", "content-type", "x-amz-content-sha256", "x-amz-date", "x-amz-security-token"]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
variable "cors_allow_methods" {
|
|
50
|
+
description = "List of allowed HTTP methods for CORS"
|
|
51
|
+
type = list(string)
|
|
52
|
+
default = ["*"]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
variable "cors_allow_origins" {
|
|
56
|
+
description = "List of allowed origins for CORS"
|
|
57
|
+
type = list(string)
|
|
58
|
+
default = ["*"]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Tags
|
|
62
|
+
variable "tags" {
|
|
63
|
+
description = "Tags to apply to all resources"
|
|
64
|
+
type = map(string)
|
|
65
|
+
default = {}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# Get current AWS region and account ID
|
|
69
|
+
data "aws_region" "current" {}
|
|
70
|
+
data "aws_caller_identity" "current" {}
|
|
71
|
+
|
|
72
|
+
# Resources
|
|
73
|
+
|
|
74
|
+
# Create Lambda ZIP file from the FastAPI bundle directory
|
|
75
|
+
data "archive_file" "lambda_zip" {
|
|
76
|
+
type = "zip"
|
|
77
|
+
source_dir = "${path.module}/../../../../../../../dist/<%- backend.dir %>/bundle"
|
|
78
|
+
output_path = "${path.module}/../../../../../../../dist/packages/common/terraform/apis/<%- apiNameKebabCase %>/lambda.zip"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Use the core REST API module
|
|
82
|
+
module "rest_api" {
|
|
83
|
+
source = "../../../core/api/rest-api"
|
|
84
|
+
|
|
85
|
+
api_name = "<%- apiNameClassName %>"
|
|
86
|
+
api_description = "<%- apiNameClassName %> REST API"
|
|
87
|
+
stage_name = "prod"
|
|
88
|
+
stage_auto_deploy = true
|
|
89
|
+
|
|
90
|
+
# CORS Configuration
|
|
91
|
+
cors_allow_headers = var.cors_allow_headers
|
|
92
|
+
cors_allow_methods = var.cors_allow_methods
|
|
93
|
+
cors_allow_origins = var.cors_allow_origins
|
|
94
|
+
|
|
95
|
+
# Tags
|
|
96
|
+
tags = var.tags
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# Lambda function
|
|
100
|
+
resource "aws_lambda_function" "api_lambda" {
|
|
101
|
+
#checkov:skip=CKV_AWS_117:Lambda function does not need to be in VPC for this use case
|
|
102
|
+
#checkov:skip=CKV_AWS_116:Dead Letter Queue not required for this simple API use case
|
|
103
|
+
#checkov:skip=CKV_AWS_272:Code signing not required for this use case
|
|
104
|
+
#checkov:skip=CKV_AWS_115:Concurrent execution limit not required for this use case
|
|
105
|
+
#checkov:skip=CKV_AWS_173:Lambda environment variables encrypted by managed key
|
|
106
|
+
filename = data.archive_file.lambda_zip.output_path
|
|
107
|
+
function_name = "<%- apiNameClassName %>Handler"
|
|
108
|
+
role = aws_iam_role.lambda_execution_role.arn
|
|
109
|
+
<%_ if (backend.type === 'trpc') { _%>
|
|
110
|
+
handler = "index.handler"
|
|
111
|
+
runtime = "nodejs22.x"
|
|
112
|
+
<%_ } else if (backend.type === 'fastapi') { _%>
|
|
113
|
+
handler = "<%= backend.moduleName %>.main.handler"
|
|
114
|
+
runtime = "python3.12"
|
|
115
|
+
<%_ } _%>
|
|
116
|
+
timeout = 30
|
|
117
|
+
memory_size = 128
|
|
118
|
+
|
|
119
|
+
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
|
|
120
|
+
|
|
121
|
+
# Enable X-Ray tracing
|
|
122
|
+
tracing_config {
|
|
123
|
+
mode = "Active"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
environment {
|
|
127
|
+
variables = merge({
|
|
128
|
+
AWS_CONNECTION_REUSE_ENABLED = "1"
|
|
129
|
+
}, var.env)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
tags = var.tags
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# IAM role for Lambda execution
|
|
136
|
+
resource "aws_iam_role" "lambda_execution_role" {
|
|
137
|
+
name = "<%- apiNameClassName %>Handler-execution-role"
|
|
138
|
+
|
|
139
|
+
assume_role_policy = jsonencode({
|
|
140
|
+
Version = "2012-10-17"
|
|
141
|
+
Statement = [
|
|
142
|
+
{
|
|
143
|
+
Action = "sts:AssumeRole"
|
|
144
|
+
Effect = "Allow"
|
|
145
|
+
Principal = {
|
|
146
|
+
Service = "lambda.amazonaws.com"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
tags = var.tags
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Attach basic execution policy to Lambda role
|
|
156
|
+
resource "aws_iam_role_policy_attachment" "lambda_basic_execution" {
|
|
157
|
+
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
|
|
158
|
+
role = aws_iam_role.lambda_execution_role.name
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
# Attach X-Ray tracing policy to Lambda role
|
|
162
|
+
resource "aws_iam_role_policy_attachment" "lambda_xray_execution" {
|
|
163
|
+
policy_arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
|
|
164
|
+
role = aws_iam_role.lambda_execution_role.name
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Additional IAM policies for Lambda (if provided)
|
|
168
|
+
resource "aws_iam_role_policy" "lambda_additional_policies" {
|
|
169
|
+
count = length(var.additional_iam_policy_statements) > 0 ? 1 : 0
|
|
170
|
+
name = "<%- apiNameClassName %>Handler-additional-policies"
|
|
171
|
+
role = aws_iam_role.lambda_execution_role.id
|
|
172
|
+
|
|
173
|
+
policy = jsonencode({
|
|
174
|
+
Version = "2012-10-17"
|
|
175
|
+
Statement = var.additional_iam_policy_statements
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
# CloudWatch Log Group for Lambda
|
|
180
|
+
resource "aws_cloudwatch_log_group" "lambda_logs" {
|
|
181
|
+
#checkov:skip=CKV_AWS_158:Using default CloudWatch log encryption
|
|
182
|
+
#checkov:skip=CKV_AWS_338:Log retention set to forever
|
|
183
|
+
#checkov:skip=CKV_AWS_66:Log retention set to forever
|
|
184
|
+
name = "/aws/lambda/<%- apiNameClassName %>Handler"
|
|
185
|
+
tags = var.tags
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
<%_ if (auth === 'Cognito') { _%>
|
|
189
|
+
# Cognito User Pool Authorizer
|
|
190
|
+
resource "aws_api_gateway_authorizer" "cognito_authorizer" {
|
|
191
|
+
name = "<%- apiNameClassName %>Authorizer"
|
|
192
|
+
rest_api_id = module.rest_api.api_id
|
|
193
|
+
type = "COGNITO_USER_POOLS"
|
|
194
|
+
provider_arns = ["arn:aws:cognito-idp:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:userpool/${var.user_pool_id}"]
|
|
195
|
+
identity_source = "method.request.header.Authorization"
|
|
196
|
+
}
|
|
197
|
+
<%_ } _%>
|
|
198
|
+
|
|
199
|
+
# Create proxy resource (captures all paths)
|
|
200
|
+
resource "aws_api_gateway_resource" "proxy_resource" {
|
|
201
|
+
rest_api_id = module.rest_api.api_id
|
|
202
|
+
parent_id = module.rest_api.api_root_resource_id
|
|
203
|
+
path_part = "{proxy+}"
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
# Lambda integration for REST API
|
|
207
|
+
resource "aws_api_gateway_integration" "lambda_integration" {
|
|
208
|
+
rest_api_id = module.rest_api.api_id
|
|
209
|
+
resource_id = aws_api_gateway_resource.proxy_resource.id
|
|
210
|
+
http_method = aws_api_gateway_method.proxy_method.http_method
|
|
211
|
+
|
|
212
|
+
integration_http_method = "POST"
|
|
213
|
+
type = "AWS_PROXY"
|
|
214
|
+
uri = aws_lambda_function.api_lambda.invoke_arn
|
|
215
|
+
|
|
216
|
+
depends_on = [aws_lambda_function.api_lambda]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
# Method for proxy integration
|
|
220
|
+
resource "aws_api_gateway_method" "proxy_method" {
|
|
221
|
+
#checkov:skip=CKV2_AWS_53:Request validation not required for proxy integration as Lambda handles validation
|
|
222
|
+
rest_api_id = module.rest_api.api_id
|
|
223
|
+
resource_id = aws_api_gateway_resource.proxy_resource.id
|
|
224
|
+
http_method = "ANY"
|
|
225
|
+
|
|
226
|
+
<%_ if (auth === 'IAM') { _%>
|
|
227
|
+
authorization = "AWS_IAM"
|
|
228
|
+
<%_ } else if (auth === 'Cognito') { _%>
|
|
229
|
+
authorization = "COGNITO_USER_POOLS"
|
|
230
|
+
authorizer_id = aws_api_gateway_authorizer.cognito_authorizer.id
|
|
231
|
+
<%_ } else if (auth === 'None') { _%>
|
|
232
|
+
# Note: you may wish to suppress the checkov rule CKV_AWS_59 if you are absolutely sure you
|
|
233
|
+
# need a public API without authentication
|
|
234
|
+
authorization = "NONE"
|
|
235
|
+
<%_ } _%>
|
|
236
|
+
|
|
237
|
+
request_parameters = {
|
|
238
|
+
"method.request.path.proxy" = true
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
depends_on = [<% if (auth === 'Cognito') { %>aws_api_gateway_authorizer.cognito_authorizer<% } %>]
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
# OPTIONS method for CORS preflight
|
|
245
|
+
resource "aws_api_gateway_method" "options_method" {
|
|
246
|
+
#checkov:skip=CKV2_AWS_70:OPTIONS method must be unauthenticated for CORS preflight requests
|
|
247
|
+
#checkov:skip=CKV2_AWS_53:Request validation not required for OPTIONS CORS preflight method
|
|
248
|
+
rest_api_id = module.rest_api.api_id
|
|
249
|
+
resource_id = aws_api_gateway_resource.proxy_resource.id
|
|
250
|
+
http_method = "OPTIONS"
|
|
251
|
+
authorization = "NONE"
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
# CORS integration for OPTIONS method
|
|
255
|
+
resource "aws_api_gateway_integration" "options_integration" {
|
|
256
|
+
rest_api_id = module.rest_api.api_id
|
|
257
|
+
resource_id = aws_api_gateway_resource.proxy_resource.id
|
|
258
|
+
http_method = aws_api_gateway_method.options_method.http_method
|
|
259
|
+
|
|
260
|
+
type = "MOCK"
|
|
261
|
+
request_templates = {
|
|
262
|
+
"application/json" = "{\"statusCode\": 204}"
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
# OPTIONS method response
|
|
267
|
+
resource "aws_api_gateway_method_response" "options_response" {
|
|
268
|
+
rest_api_id = module.rest_api.api_id
|
|
269
|
+
resource_id = aws_api_gateway_resource.proxy_resource.id
|
|
270
|
+
http_method = aws_api_gateway_method.options_method.http_method
|
|
271
|
+
status_code = "204"
|
|
272
|
+
|
|
273
|
+
response_parameters = {
|
|
274
|
+
"method.response.header.Access-Control-Allow-Headers" = true
|
|
275
|
+
"method.response.header.Access-Control-Allow-Methods" = true
|
|
276
|
+
"method.response.header.Access-Control-Allow-Origin" = true
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
# OPTIONS integration response
|
|
281
|
+
resource "aws_api_gateway_integration_response" "options_integration_response" {
|
|
282
|
+
rest_api_id = module.rest_api.api_id
|
|
283
|
+
resource_id = aws_api_gateway_resource.proxy_resource.id
|
|
284
|
+
http_method = aws_api_gateway_method.options_method.http_method
|
|
285
|
+
status_code = aws_api_gateway_method_response.options_response.status_code
|
|
286
|
+
|
|
287
|
+
response_parameters = {
|
|
288
|
+
"method.response.header.Access-Control-Allow-Headers" = "'${join(",", var.cors_allow_headers)}'"
|
|
289
|
+
"method.response.header.Access-Control-Allow-Methods" = "'${join(",", var.cors_allow_methods)}'"
|
|
290
|
+
"method.response.header.Access-Control-Allow-Origin" = "'${join(",", var.cors_allow_origins)}'"
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
# API Gateway deployment
|
|
295
|
+
resource "aws_api_gateway_deployment" "api_deployment" {
|
|
296
|
+
rest_api_id = module.rest_api.api_id
|
|
297
|
+
|
|
298
|
+
triggers = {
|
|
299
|
+
redeployment = sha1(jsonencode([
|
|
300
|
+
aws_api_gateway_resource.proxy_resource.id,
|
|
301
|
+
aws_api_gateway_method.proxy_method.id,
|
|
302
|
+
aws_api_gateway_integration.lambda_integration.id,
|
|
303
|
+
aws_api_gateway_method.options_method.id,
|
|
304
|
+
aws_api_gateway_integration.options_integration.id,
|
|
305
|
+
]))
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
lifecycle {
|
|
309
|
+
create_before_destroy = true
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
depends_on = [
|
|
313
|
+
aws_api_gateway_method.proxy_method,
|
|
314
|
+
aws_api_gateway_integration.lambda_integration,
|
|
315
|
+
aws_api_gateway_method.options_method,
|
|
316
|
+
aws_api_gateway_integration.options_integration,
|
|
317
|
+
aws_api_gateway_method_response.options_response,
|
|
318
|
+
aws_api_gateway_integration_response.options_integration_response,
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
# API Gateway stage
|
|
323
|
+
resource "aws_api_gateway_stage" "api_stage" {
|
|
324
|
+
#checkov:skip=CKV_AWS_120:API Gateway caching not required for this use case
|
|
325
|
+
#checkov:skip=CKV_AWS_76:API Gateway access logging disabled due to account-level CloudWatch Logs role ARN requirement
|
|
326
|
+
#checkov:skip=CKV2_AWS_4:API Gateway logging level not applicable as access logging is disabled
|
|
327
|
+
#checkov:skip=CKV2_AWS_51:Client certificate authentication not required for this use case
|
|
328
|
+
deployment_id = aws_api_gateway_deployment.api_deployment.id
|
|
329
|
+
rest_api_id = module.rest_api.api_id
|
|
330
|
+
stage_name = "prod"
|
|
331
|
+
xray_tracing_enabled = true
|
|
332
|
+
|
|
333
|
+
tags = var.tags
|
|
334
|
+
|
|
335
|
+
depends_on = [aws_api_gateway_deployment.api_deployment]
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
# API Gateway Resource Policy
|
|
339
|
+
resource "aws_api_gateway_rest_api_policy" "api_policy" {
|
|
340
|
+
rest_api_id = module.rest_api.api_id
|
|
341
|
+
|
|
342
|
+
policy = jsonencode({
|
|
343
|
+
Version = "2012-10-17"
|
|
344
|
+
Statement = [
|
|
345
|
+
<%_ if (auth === 'IAM') { _%>
|
|
346
|
+
{
|
|
347
|
+
# Grant any AWS credentials from the account to call the API
|
|
348
|
+
# Machine to machine fine-grained access can be defined here using more specific principals
|
|
349
|
+
# (eg roles or users) and resources (eg which api paths may be invoked by which principal) if required
|
|
350
|
+
Effect = "Allow"
|
|
351
|
+
Principal = {
|
|
352
|
+
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
|
|
353
|
+
}
|
|
354
|
+
Action = "execute-api:Invoke"
|
|
355
|
+
Resource = "execute-api:/*"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
# Open up OPTIONS to allow browsers to make unauthenticated preflight requests
|
|
359
|
+
Effect = "Allow"
|
|
360
|
+
Principal = "*"
|
|
361
|
+
Action = "execute-api:Invoke"
|
|
362
|
+
Resource = "execute-api:/*/OPTIONS/*"
|
|
363
|
+
}
|
|
364
|
+
<%_ } else { _%>
|
|
365
|
+
{
|
|
366
|
+
# Allow all callers to invoke the API in the resource policy<% if (auth === 'Cognito') { %>, since auth is handled by Cognito<% } %>
|
|
367
|
+
Effect = "Allow"
|
|
368
|
+
Principal = "*"
|
|
369
|
+
Action = "execute-api:Invoke"
|
|
370
|
+
Resource = "execute-api:/*"
|
|
371
|
+
}
|
|
372
|
+
<%_ } _%>
|
|
373
|
+
]
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
# Lambda permission for API Gateway to invoke the function
|
|
378
|
+
resource "aws_lambda_permission" "api_gateway_invoke" {
|
|
379
|
+
statement_id = "AllowExecutionFromAPIGateway"
|
|
380
|
+
action = "lambda:InvokeFunction"
|
|
381
|
+
function_name = aws_lambda_function.api_lambda.function_name
|
|
382
|
+
principal = "apigateway.amazonaws.com"
|
|
383
|
+
source_arn = "${module.rest_api.api_execution_arn}/*/*"
|
|
384
|
+
|
|
385
|
+
depends_on = [module.rest_api, aws_lambda_function.api_lambda]
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
# Outputs
|
|
389
|
+
|
|
390
|
+
# API Gateway Outputs (from core module)
|
|
391
|
+
output "api_id" {
|
|
392
|
+
description = "ID of the REST API Gateway"
|
|
393
|
+
value = module.rest_api.api_id
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
output "api_arn" {
|
|
397
|
+
description = "ARN of the REST API Gateway"
|
|
398
|
+
value = module.rest_api.api_arn
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
output "api_endpoint" {
|
|
402
|
+
description = "Base URL of the REST API Gateway"
|
|
403
|
+
value = module.rest_api.api_endpoint
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
output "api_execution_arn" {
|
|
407
|
+
description = "Execution ARN of the REST API Gateway"
|
|
408
|
+
value = module.rest_api.api_execution_arn
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
output "stage_invoke_url" {
|
|
412
|
+
description = "Invoke URL of the API Gateway stage"
|
|
413
|
+
value = aws_api_gateway_stage.api_stage.invoke_url
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
output "stage_arn" {
|
|
417
|
+
description = "ARN of the API Gateway stage"
|
|
418
|
+
value = aws_api_gateway_stage.api_stage.arn
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
output "stage_execution_arn" {
|
|
422
|
+
description = "Execution ARN of the API Gateway stage"
|
|
423
|
+
value = aws_api_gateway_stage.api_stage.execution_arn
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
output "deployment_id" {
|
|
427
|
+
description = "ID of the API Gateway deployment"
|
|
428
|
+
value = aws_api_gateway_deployment.api_deployment.id
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
output "stage_id" {
|
|
432
|
+
description = "ID of the API Gateway stage"
|
|
433
|
+
value = aws_api_gateway_stage.api_stage.id
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
# Lambda Function Outputs
|
|
437
|
+
output "lambda_function_name" {
|
|
438
|
+
description = "Name of the Lambda function"
|
|
439
|
+
value = aws_lambda_function.api_lambda.function_name
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
output "lambda_function_arn" {
|
|
443
|
+
description = "ARN of the Lambda function"
|
|
444
|
+
value = aws_lambda_function.api_lambda.arn
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
output "lambda_invoke_arn" {
|
|
448
|
+
description = "Invoke ARN of the Lambda function"
|
|
449
|
+
value = aws_lambda_function.api_lambda.invoke_arn
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
output "lambda_qualified_arn" {
|
|
453
|
+
description = "Qualified ARN of the Lambda function"
|
|
454
|
+
value = aws_lambda_function.api_lambda.qualified_arn
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
output "lambda_version" {
|
|
458
|
+
description = "Version of the Lambda function"
|
|
459
|
+
value = aws_lambda_function.api_lambda.version
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
output "lambda_source_code_hash" {
|
|
463
|
+
description = "Base64-encoded SHA256 hash of the Lambda deployment package"
|
|
464
|
+
value = aws_lambda_function.api_lambda.source_code_hash
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
output "lambda_source_code_size" {
|
|
468
|
+
description = "Size of the Lambda deployment package in bytes"
|
|
469
|
+
value = aws_lambda_function.api_lambda.source_code_size
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
# IAM Role Outputs
|
|
473
|
+
output "lambda_execution_role_arn" {
|
|
474
|
+
description = "ARN of the Lambda execution role"
|
|
475
|
+
value = aws_iam_role.lambda_execution_role.arn
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
output "lambda_execution_role_name" {
|
|
479
|
+
description = "Name of the Lambda execution role"
|
|
480
|
+
value = aws_iam_role.lambda_execution_role.name
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
# Integration Outputs
|
|
484
|
+
output "integration_id" {
|
|
485
|
+
description = "ID of the Lambda integration"
|
|
486
|
+
value = aws_api_gateway_integration.lambda_integration.id
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
output "proxy_resource_id" {
|
|
490
|
+
description = "ID of the proxy resource"
|
|
491
|
+
value = aws_api_gateway_resource.proxy_resource.id
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
output "proxy_method_id" {
|
|
495
|
+
description = "ID of the proxy method"
|
|
496
|
+
value = aws_api_gateway_method.proxy_method.id
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
# CloudWatch Log Groups
|
|
500
|
+
output "lambda_log_group_name" {
|
|
501
|
+
description = "Name of the Lambda CloudWatch log group"
|
|
502
|
+
value = aws_cloudwatch_log_group.lambda_logs.name
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
output "lambda_log_group_arn" {
|
|
506
|
+
description = "ARN of the Lambda CloudWatch log group"
|
|
507
|
+
value = aws_cloudwatch_log_group.lambda_logs.arn
|
|
508
|
+
}
|