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

[CDS-1576] resource type filter & AP3 region - PR again #156

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lambda-secretLayer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## lambda-secretLayer

### 0.0.3 / 25.8.2024
* [update] Allow the layer to run in nodejs20 applications.

### 0.0.2 / 1.10.2023
* [Change] Change SSM option in the integration to SM - Secret Manager.

Expand Down
4 changes: 2 additions & 2 deletions src/lambda-secretLayer/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ Metadata:
- lambda
- extension
HomePageUrl: https://coralogix.com
SemanticVersion: 1.0.2
SemanticVersion: 1.0.3
SourceCodeUrl: https://github.com/coralogix/coralogix-aws-serverless
Parameters:
CompatibleRuntimes:
Type: CommaDelimitedList
Description: Lambda Layer Version compatible runtimes
Default: nodejs16.x, nodejs18.x, nodejs14.x
Default: nodejs16.x, nodejs18.x, nodejs14.x, nodejs20.x
RetentionPolicy:
Type: String
Description: Lambda Layer Version retention policy
Expand Down
6 changes: 3 additions & 3 deletions src/lambda-secretLayer/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

node_version=$(node -e "console.log(process.version)")

if [[ $node_version == v18.* ]]; then
node /opt/wrapper18.js
if [[ $node_version == v16.* || $node_version == v14.* ]]; then
node /opt/wrapper16.js
#cat /tmp/envVars

source /tmp/envVars
else
node /opt/wrapper16.js
node /opt/wrapper18.js
#cat /tmp/envVars

source /tmp/envVars
Expand Down
Binary file modified src/lambda-secretLayer/wrapper.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions src/resource-metadata/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## resource-metadata

### 1.2.10 / 09.10.2024
* [Update] Add resource type filter to exclude either lambda and ec2 resources.
* [Update] Add AP3 region to the list of regions.

### 1.2.9 / 21.05.2024
* [Update] Align Regions names with other integration .i.e EU1,EU2...

Expand Down
3 changes: 2 additions & 1 deletion src/resource-metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ This application collect AWS resource metadata and sends them to your **Coralogi

| Parameter | Description | Default Value | Required |
|---|---|---|---|
| CoralogixRegion | The Coralogix location region, possible options are [EU1, EU2, AP1, AP2, US1, US2, Custom].In case that you want to use Custom domain, leave this as default and write the Custom doamin in the ``CustomDomain`` filed. | Custom | :heavy_check_mark: |
| CoralogixRegion | The Coralogix location region, possible options are [EU1, EU2, AP1, AP2, AP3, US1, US2, Custom].In case that you want to use Custom domain, leave this as default and write the Custom doamin in the ``CustomDomain`` filed. | Custom | :heavy_check_mark: |
| CustomDomain | The Coralogix custom domain, leave empty if you don't use Custom domain. | | |
| aplication name | The stack name of this application created via AWS CloudFormation. | | :heavy_check_mark: |
| CreateSecret | Set to False In case you want to use secrets manager with a predefine secret that was already created and contains Coralogix Send Your Data API key. | True | |
| ApiKey | Your [Coralogix Send Your Data – API Key](https://coralogix.com/docs/send-your-data-api-key/) or incase you use pre created secret (created in AWS secret manager) put here the name of the secret that contains the Coralogix send your data key | | :heavy_check_mark: |
| ResourceTtlMinutes | Once a resource is collected, how long should it remain valid. | 60 | |
| LatestVersionsPerFunction | How many latest published versions of each Lambda function should be collected. | 0 | |
| CollectAliases | [True/False] | False | |
| ResourceTypeFilter | Specify a resource type to filter out. Possible options are [`ec2`, `lambda`] | | |
| LambdaFunctionIncludeRegexFilter | If specified, only lambda functions with ARNs matching the regex will be included in the collected metadata | | |
| LambdaFunctionExcludeRegexFilter | If specified, only lambda functions with ARNs NOT matching the regex will be included in the collected metadata | | |
| LambdaFunctionTagFilters | If specified, only lambda functions with tags matching the filters will be included in the collected metadata. Values should follow the JSON syntax for --tag-filters as documented [here](https://docs.aws.amazon.com/cli/latest/reference/resourcegroupstaggingapi/get-resources.html#options) | | |
Expand Down
21 changes: 18 additions & 3 deletions src/resource-metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import { collectLambdaResources, parseLambdaFunctionArn } from './lambda.js'
import { sendToCoralogix } from './coralogix.js'
import { collectEc2Resources } from './ec2.js';

const validateAndExtractConfiguration = () => {
const excludeEC2 = String(process.env.IS_EC2_RESOURCE_TYPE_EXCLUDED).toLowerCase() === "true"
const excludeLambda = String(process.env.IS_LAMBDA_RESOURCE_TYPE_EXCLUDED).toLowerCase() === "true"
return { excludeEC2, excludeLambda };
}
const { excludeEC2, excludeLambda } = validateAndExtractConfiguration();

/**
* @description Lambda function handler
*/
Expand All @@ -22,10 +29,18 @@ export const handler = async (_, context) => {
const collectorId = `arn:aws:lambda:${invokedArn.region}:${invokedArn.accountId}:function:${invokedArn.functionName}`
console.info(`Collector ${collectorId} starting collection`)

const lambda = collectAndSendLambdaResources(collectorId)
const ec2 = collectAndSendEc2Resources(collectorId, invokedArn.region, invokedArn.accountId)
let dataToCollect = []

if(!excludeEC2) {
const ec2 = collectAndSendEc2Resources(collectorId, invokedArn.region, invokedArn.accountId)
dataToCollect.push(ec2)
}

await Promise.all([lambda, ec2])
if(!excludeLambda) {
const lambda = collectAndSendLambdaResources(collectorId)
dataToCollect.push(lambda)
}
await Promise.all(dataToCollect)

console.info("Collection done")
}
Expand Down
2 changes: 1 addition & 1 deletion src/resource-metadata/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coralogix-resource-tags",
"title": "AWS Resource Tags Lambda function for Coralogix",
"version": "1.2.8",
"version": "1.2.10",
"description": "AWS Lambda function to send AWS resource tags to Coralogix",
"homepage": "https://coralogix.com",
"license": "Apache-2.0",
Expand Down
137 changes: 98 additions & 39 deletions src/resource-metadata/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Metadata:
- coralogix
- metadata
HomePageUrl: https://coralogix.com
SemanticVersion: 1.2.9
SemanticVersion: 1.2.10
SourceCodeUrl: https://github.com/coralogix/coralogix-aws-serverless
AWS::CloudFormation::Interface:
ParameterGroups:
Expand All @@ -34,6 +34,8 @@ Metadata:
- LambdaFunctionExcludeRegexFilter
- LambdaFunctionTagFilters
- NotificationEmail
- IsEC2ResourceTypeExcluded
- IsLambdaResourceTypeExcluded
- Label:
default: Lambda Configuration
Parameters:
Expand Down Expand Up @@ -76,6 +78,10 @@ Metadata:
default: Timeout
NotificationEmail:
default: Notification Email
IsEC2ResourceTypeExcluded:
default: Is EC2 Resource Type Excluded?
IsLambdaResourceTypeExcluded:
default: Is Lambda Resource Type Excluded?
Parameters:
CoralogixRegion:
Type: String
Expand All @@ -85,6 +91,7 @@ Parameters:
- EU2
- AP1
- AP2
- AP3
- US1
- US2
- Custom
Expand Down Expand Up @@ -159,6 +166,20 @@ Parameters:
Type: String
Description: Set to False In case you want to use secrets manager with a predefine secret that was already created and contains Coralogix Send Your Data API key.
Default: 'True'
IsEC2ResourceTypeExcluded:
Type: String
Description: Is EC2 Resource Type Excluded?
AllowedValues:
- 'True'
- 'False'
Default: 'False'
IsLambdaResourceTypeExcluded:
Type: String
Description: Is Lambda Resource Type Excluded?
AllowedValues:
- 'True'
- 'False'
Default: 'False'
Mappings:
CoralogixRegionMap:
EU1:
Expand All @@ -169,6 +190,8 @@ Mappings:
MetadataUrl: app.coralogix.in
AP2:
MetadataUrl: coralogixsg.com
AP3:
MetadataUrl: ap3.coralogix.com
US1:
MetadataUrl: coralogix.us
US2:
Expand Down Expand Up @@ -201,6 +224,14 @@ Conditions:
- Fn::Equals:
- Ref: CreateSecret
- 'True'
IsEC2ResourceTypeExcluded:
Fn::Equals:
- Ref: IsEC2ResourceTypeExcluded
- 'True'
IsLambdaResourceTypeExcluded:
Fn::Equals:
- Ref: IsLambdaResourceTypeExcluded
- 'True'
Resources:
LambdaFunction:
Condition: IsNotSMEnabled
Expand Down Expand Up @@ -242,6 +273,14 @@ Resources:
Ref: LambdaFunctionTagFilters
AWS_RETRY_MODE: adaptive
AWS_MAX_ATTEMPTS: 10
IS_EC2_RESOURCE_TYPE_EXCLUDED: !If
- IsEC2ResourceTypeExcluded
- 'true'
- 'false'
IS_LAMBDA_RESOURCE_TYPE_EXCLUDED: !If
- IsLambdaResourceTypeExcluded
- 'true'
- 'false'
Events:
ScheduledEvent:
Type: Schedule
Expand All @@ -254,25 +293,31 @@ Resources:
OnFailure:
Type: SNS
Policies:
- Version: "2012-10-17"
Statement:
- Sid: GetEc2Metadata
Effect: Allow
Action:
- ec2:DescribeInstances
Resource: "*"
- Version: "2012-10-17"
Statement:
- Sid: GetLambdaMetadata
Effect: Allow
Action:
- lambda:ListFunctions
- lambda:ListVersionsByFunction
- lambda:GetFunction
- lambda:ListAliases
- lambda:ListEventSourceMappings
- lambda:GetPolicy
Resource: "*"
- !If
- IsEC2ResourceTypeExcluded
- Version: "2012-10-17"
Statement:
- Sid: GetEc2Metadata
Effect: Allow
Action:
- ec2:DescribeInstances
Resource: "*"
- !Ref 'AWS::NoValue'
- !If:
- IsLambdaResourceTypeExcluded
- Version: "2012-10-17"
Statement:
- Sid: GetLambdaMetadata
Effect: Allow
Action:
- lambda:ListFunctions
- lambda:ListVersionsByFunction
- lambda:GetFunction
- lambda:ListAliases
- lambda:ListEventSourceMappings
- lambda:GetPolicy
Resource: "*"
- !Ref 'AWS::NoValue'
- Version: "2012-10-17"
Statement:
- Sid: GetResourcesByTags
Expand Down Expand Up @@ -325,6 +370,14 @@ Resources:
- CreateSecret
- ""
- Ref: ApiKey
IS_EC2_RESOURCE_TYPE_EXCLUDED: !If
- IsEC2ResourceTypeExcluded
- 'true'
- 'false'
IS_LAMBDA_RESOURCE_TYPE_EXCLUDED: !If
- IsLambdaResourceTypeExcluded
- 'true'
- 'false'
Events:
ScheduledEvent:
Type: Schedule
Expand All @@ -337,25 +390,31 @@ Resources:
OnFailure:
Type: SNS
Policies:
- Version: "2012-10-17"
Statement:
- Sid: GetEc2Metadata
Effect: Allow
Action:
- ec2:DescribeInstances
Resource: "*"
- Version: "2012-10-17"
Statement:
- Sid: GetLambdaMetadata
Effect: Allow
Action:
- lambda:ListFunctions
- lambda:ListVersionsByFunction
- lambda:GetFunction
- lambda:ListAliases
- lambda:ListEventSourceMappings
- lambda:GetPolicy
Resource: "*"
- !If
- IsEC2ResourceTypeExcluded
- Version: "2012-10-17"
Statement:
- Sid: GetEc2Metadata
Effect: Allow
Action:
- ec2:DescribeInstances
Resource: "*"
- !Ref "AWS::NoValue"
- !If:
- IsLambdaResourceTypeExcluded
- Version: "2012-10-17"
Statement:
- Sid: GetLambdaMetadata
Effect: Allow
Action:
- lambda:ListFunctions
- lambda:ListVersionsByFunction
- lambda:GetFunction
- lambda:ListAliases
- lambda:ListEventSourceMappings
- lambda:GetPolicy
Resource: "*"
- !Ref "AWS::NoValue"
- Version: "2012-10-17"
Statement:
- Sid: GetResourcesByTags
Expand Down
Loading