From c3a2f0cdee7e482264164c4ac7444be56d8825f2 Mon Sep 17 00:00:00 2001
From: edebrye <edebrye@ippon.fr>
Date: Tue, 16 Mar 2021 11:11:56 +0100
Subject: [PATCH] Added X-Ray on api gw and lambdas

---
 README.md                 | 7 +++++++
 deploy/api-gateway.tf     | 9 +++++----
 deploy/docker-compose.yml | 2 +-
 deploy/lambda.tf          | 4 ++++
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 7789982..3fcf324 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,9 @@
 # cloud-monitor
 
+## Run some integration tests
+
+```bash
+docker run --rm -itv $PWD:/etc/newman/ postman/newman run --env-var endpoint={api_gateway_endpoint} Lambda_CRUD.postman_collection.json
+```
+
+Useful for testing and/or generate logs.
diff --git a/deploy/api-gateway.tf b/deploy/api-gateway.tf
index 91282bd..f8443d9 100644
--- a/deploy/api-gateway.tf
+++ b/deploy/api-gateway.tf
@@ -82,10 +82,11 @@ resource "aws_api_gateway_deployment" "main" {
 }
 
 resource "aws_api_gateway_stage" "main" {
-  deployment_id = aws_api_gateway_deployment.main.id
-  rest_api_id   = aws_api_gateway_rest_api.main.id
-  stage_name    = terraform.workspace == "production" ? "api" : terraform.workspace
-  tags          = local.common_tags
+  deployment_id        = aws_api_gateway_deployment.main.id
+  rest_api_id          = aws_api_gateway_rest_api.main.id
+  stage_name           = terraform.workspace == "production" ? "api" : terraform.workspace
+  xray_tracing_enabled = true
+  tags                 = local.common_tags
 }
 
 resource "aws_api_gateway_method_settings" "general_settings" {
diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml
index 4263e73..beb2ec4 100644
--- a/deploy/docker-compose.yml
+++ b/deploy/docker-compose.yml
@@ -2,7 +2,7 @@ version: '3.7'
 
 services:
   terraform:
-    image: hashicorp/terraform:0.14.7
+    image: hashicorp/terraform:0.14.8
     volumes:
       - .:/infra
     working_dir: /infra
diff --git a/deploy/lambda.tf b/deploy/lambda.tf
index 9406a4a..19235e3 100644
--- a/deploy/lambda.tf
+++ b/deploy/lambda.tf
@@ -16,6 +16,10 @@ resource "aws_lambda_function" "crud" {
     "arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:14"
   ]
 
+  tracing_config {
+    mode = "Active"
+  }
+
   environment {
     variables = {
       TABLE_NAME = aws_dynamodb_table.main.name
-- 
GitLab