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

New serverless pattern - EventBridge Scheduler to invoke Step Functions to get the List of Inactive Lambda functions #2533

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sahilk225579
Copy link

Issue #, if available:

Description of changes:

added all the required SAM template, lambda function code & state machine defination.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

@marcojahn marcojahn left a comment

Choose a reason for hiding this comment

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

@@ -0,0 +1,85 @@
# EventBridge scheduler to invoke step function to get the list of inactive lambda functions
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# EventBridge scheduler to invoke step function to get the list of inactive lambda functions
# Amazon EventBridge Scheduler to invoke an AWS Step Function to get the list of inactive AWS Lambda functions

@@ -0,0 +1,85 @@
# EventBridge scheduler to invoke step function to get the list of inactive lambda functions

This pattern will create a one time schedule in EventBridge scheduler with state machine as target & invoke the lambda ListFunctions & GetFunction API using the SDK integration in step functions and publish the list of inactive functions to SNS Topic.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This pattern will create a one time schedule in EventBridge scheduler with state machine as target & invoke the lambda ListFunctions & GetFunction API using the SDK integration in step functions and publish the list of inactive functions to SNS Topic.
This pattern will create an Amazon EventBridge Scheduler rule targeting an AWS Step Function state machine. The Step Function invokes an AWS Lambda using `ListFunctions` and `GetFunctions` API using the SDK integration in Step Functions. It publishes the list of inactive functions to an Amazon SNS Topic.


6. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.

7. **Imp** : Once the SNS topic & subscription is created, verify the subscription by clicking the 'Confirm subscription' link received on your email.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
7. **Imp** : Once the SNS topic & subscription is created, verify the subscription by clicking the 'Confirm subscription' link received on your email.
7. **Important** : Once the SNS topic & subscription is created, verify the subscription by clicking the 'Confirm subscription' link received on your email.

"Imp" means "important"?


## How it works

1. When the stack is deployed it creates a state machine, an eventBridge scheduler,a SNS topic with email subscription, a Lambda Function and required IAM roles.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
1. When the stack is deployed it creates a state machine, an eventBridge scheduler,a SNS topic with email subscription, a Lambda Function and required IAM roles.
1. When the stack is deployed it creates a state machine, an Event Bridge Scheduler, an SNS topic with email subscription, a Lambda function and required IAM roles.


1. When the stack is deployed it creates a state machine, an eventBridge scheduler,a SNS topic with email subscription, a Lambda Function and required IAM roles.

2. Event Bridge scheduler invokes the State machine on defined schedule, Default schedule invokes the state machine daily at 00::00 UTC with the below mentioned payload. Modify the schedule as per your requirement.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
2. Event Bridge scheduler invokes the State machine on defined schedule, Default schedule invokes the state machine daily at 00::00 UTC with the below mentioned payload. Modify the schedule as per your requirement.
2. Event Bridge Scheduler invokes the state machine with a defined schedule. The default schedule invokes the state machine daily at 00:00 UTC with the below mentioned payload. Modify the schedule as per your requirement.


3) In state machine, the 1st step is to get the list of all lambda functions in the current region using the ListFunctions API, ListFunctions API is called multiple times as it returns max 50 functions list in a single API call along with NextMarker pagination parameter. Using NextMarker token state machine retrieves list of all the function ARN's.

4) Lambda Invoke Combine data Step : This a custom lambda function python script to create a combined json array of Lambda function ARN's retrieved in step 1.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
4) Lambda Invoke Combine data Step : This a custom lambda function python script to create a combined json array of Lambda function ARN's retrieved in step 1.
4) Lambda Invoke Combine data Step : This a custom Lambda function python script to create a combined JSON array of Lambda function ARNs retrieved in step 1.


4) Lambda Invoke Combine data Step : This a custom lambda function python script to create a combined json array of Lambda function ARN's retrieved in step 1.

5) Map - Loop Functions State : In this state, GetFunction API is called for each Lambda ARN taken as input from previous step & status of each function is checked and appended to the output.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
5) Map - Loop Functions State : In this state, GetFunction API is called for each Lambda ARN taken as input from previous step & status of each function is checked and appended to the output.
5) Map - loop functions state: In this state, the GetFunction API is called for each Lambda ARN taken as input from the previous step, and the status of each function is checked and appended to the output.


5) Map - Loop Functions State : In this state, GetFunction API is called for each Lambda ARN taken as input from previous step & status of each function is checked and appended to the output.

6) Filter Inactive Functions State : This filters out the Active functions from the Json array and passes only the Inactive functions list to the next step.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
6) Filter Inactive Functions State : This filters out the Active functions from the Json array and passes only the Inactive functions list to the next step.
6) Filter inactive functions state: This filters out the active functions from the JSON array and passes only the list of inactive functions to the next step.


6) Filter Inactive Functions State : This filters out the Active functions from the Json array and passes only the Inactive functions list to the next step.

7) SNS Publish : List of Inactive functions is published to the SNS Topic.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
7) SNS Publish : List of Inactive functions is published to the SNS Topic.
7) SNS publish : List of inactive functions is published to the SNS Topic.

2. Also, you have to manually delete any schedules you created if required.

----
Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.

@marcojahn
Copy link
Contributor

Hello @sahilk225579, I've requested a few changes. After applying the PR can be processed further.
TY

@sahilk225579
Copy link
Author

added all the changes

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