Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use lambda layer and newrelic lambda handler wrapper #415

Merged
merged 8 commits into from
Mar 17, 2022

Conversation

mohdnr
Copy link
Contributor

@mohdnr mohdnr commented Mar 15, 2022

Setup environment variables required for the lambda api to successfully integrate with newrelic

related:

@mohdnr mohdnr force-pushed the feat/newrelic_lambda_layer branch from 4361bd5 to db5f453 Compare March 15, 2022 20:09
@cds-snc cds-snc deleted a comment from github-actions bot Mar 15, 2022
@mohdnr mohdnr marked this pull request as ready for review March 15, 2022 20:12
@mohdnr mohdnr requested a review from jimleroyer as a code owner March 15, 2022 20:12
@mohdnr mohdnr changed the title feat: use lambda layer and Cloudwatch for newrelic logs feat: use newrelic log ingestor Mar 15, 2022
@mohdnr mohdnr requested a review from iokpala March 15, 2022 20:12
@mohdnr mohdnr changed the title feat: use newrelic log ingestor feat: use lambda layer and newrelic lambda handler wrapper Mar 15, 2022
Copy link
Member

@jimleroyer jimleroyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try this out!

@mohdnr
Copy link
Contributor Author

mohdnr commented Mar 16, 2022

Need to make changes to notification-api before this moves forward. Putting this back to draft until then

@mohdnr mohdnr marked this pull request as draft March 16, 2022 13:42
@mohdnr mohdnr requested review from jimleroyer and removed request for jimleroyer and iokpala March 16, 2022 13:42
Copy link
Member

@jimleroyer jimleroyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright I'll remove my review and fictive request some changes until it's ready.

@github-actions
Copy link

Staging: lambda-api

✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

⚠️   WARNING: resources will be destroyed by this change!

Plan: 4 to add, 1 to change, 4 to destroy
Show plan
Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # aws_appautoscaling_scheduled_action.api-5pm must be replaced
-/+ resource "aws_appautoscaling_scheduled_action" "api-5pm" {
      ~ arn                = "arn:aws:autoscaling:ca-central-1:239043911459:scheduledAction:39be2884-1a2d-4686-b62f-4c31d1c89c01:resource/lambda/function:api-lambda:14:scheduledActionName/api-5pm" -> (known after apply)
      ~ id                 = "api-5pm-lambda-function:api-lambda:14" -> (known after apply)
        name               = "api-5pm"
      ~ resource_id        = "function:api-lambda:14" -> (known after apply) # forces replacement
        # (4 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # aws_appautoscaling_scheduled_action.api-noon must be replaced
-/+ resource "aws_appautoscaling_scheduled_action" "api-noon" {
      ~ arn                = "arn:aws:autoscaling:ca-central-1:239043911459:scheduledAction:39be2884-1a2d-4686-b62f-4c31d1c89c01:resource/lambda/function:api-lambda:14:scheduledActionName/api-noon" -> (known after apply)
      ~ id                 = "api-noon-lambda-function:api-lambda:14" -> (known after apply)
        name               = "api-noon"
      ~ resource_id        = "function:api-lambda:14" -> (known after apply) # forces replacement
        # (4 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # aws_appautoscaling_target.api must be replaced
-/+ resource "aws_appautoscaling_target" "api" {
      ~ id                 = "function:api-lambda:14" -> (known after apply)
      ~ max_capacity       = 5 -> 10
      ~ resource_id        = "function:api-lambda:14" -> (known after apply) # forces replacement
      ~ role_arn           = "arn:aws:iam::239043911459:role/aws-service-role/lambda.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_LambdaConcurrency" -> (known after apply)
        # (3 unchanged attributes hidden)
    }

  # aws_lambda_function.api will be updated in-place
  ~ resource "aws_lambda_function" "api" {
        id                             = "api-lambda"
      ~ qualified_arn                  = "arn:aws:lambda:ca-central-1:239043911459:function:api-lambda:14" -> (known after apply)
        tags                           = {}
      ~ version                        = "14" -> (known after apply)
        # (23 unchanged attributes hidden)

      ~ environment {
          ~ variables = {
              + "NEW_RELIC_ACCOUNT_ID"                  = "2691974"
              + "NEW_RELIC_EXTENSION_LOGS_ENABLED"      = "true"
              + "NEW_RELIC_LAMBDA_EXTENSION_ENABLED"    = "true"
              + "NEW_RELIC_LAMBDA_HANDLER"              = "application.handler"
                # (29 unchanged elements hidden)
            }
        }


        # (2 unchanged blocks hidden)
    }

  # aws_lambda_provisioned_concurrency_config.api must be replaced
-/+ resource "aws_lambda_provisioned_concurrency_config" "api" {
      ~ id                                = "api-lambda:14" -> (known after apply)
      ~ qualifier                         = "14" -> (known after apply) # forces replacement
        # (2 unchanged attributes hidden)
    }

Plan: 4 to add, 1 to change, 4 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Releasing state lock. This may take a few moments...
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_api_gateway_domain_name.api"]
WARN - plan.json - main - Missing Common Tags: ["aws_api_gateway_domain_name.api_lambda"]
WARN - plan.json - main - Missing Common Tags: ["aws_api_gateway_rest_api.api"]
WARN - plan.json - main - Missing Common Tags: ["aws_api_gateway_stage.api"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.api_gateway_log_group"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.notification-canada-ca-api-lambda-waf-logs"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.logs-1-error-1-minute-warning-lambda-api"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_metric_alarm.logs-10-error-5-minutes-critical-lambda-api"]
WARN - plan.json - main - Missing Common Tags: ["aws_ecr_repository.api-lambda"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.api"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.ecr"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.api"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.api_cloudwatch"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_user.ecr-user"]
WARN - plan.json - main - Missing Common Tags: ["aws_lambda_function.api"]
WARN - plan.json - main - Missing Common Tags: ["aws_secretsmanager_secret.ecr-user-access-key"]
WARN - plan.json - main - Missing Common Tags: ["aws_wafv2_web_acl.api_lambda"]

33 tests, 16 passed, 17 warnings, 0 failures, 0 exceptions

Copy link
Contributor

@sastels sastels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@mohdnr mohdnr merged commit 2297ac8 into main Mar 17, 2022
@mohdnr mohdnr deleted the feat/newrelic_lambda_layer branch March 17, 2022 14:01
mohdnr added a commit that referenced this pull request Mar 21, 2022
* feat: use lambda layer and cloudwatch for newrelic logs

* feat: send to cloudwatch for now

* chore: remove lambda layer integration

* chore: remove layer

* feat: go back to layer and wrapping the handler

* chore: remove layer

* chore: more envs

* chore: remove duplicate env
mohdnr added a commit that referenced this pull request Mar 21, 2022
* feat: use lambda layer and newrelic lambda handler wrapper (#415)

* feat: use lambda layer and cloudwatch for newrelic logs

* feat: send to cloudwatch for now

* chore: remove lambda layer integration

* chore: remove layer

* feat: go back to layer and wrapping the handler

* chore: remove layer

* chore: more envs

* chore: remove duplicate env

* chore: remove unused variables

* chore: remove unused secretmanager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants