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

Fixing msk-lambda-iam-python-sam and msk-lambda-iam-node-sam projects by adding Cloudformation templates as previous CFT doesn't work anymore due to Cloud9 dependency #2524

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

Conversation

indranilbanerjeeawssa
Copy link

Issue #, if available:

Description of changes:

Fixing msk-lambda-iam-python-sam and msk-lambda-iam-node-sam projects by adding Cloudformation templates as previous CFT doesn't work anymore due to Cloud9 dependency. Added a Cloudformation template yaml file in each of the projects MSKAndKafkaClientEC2.yaml, that installs MSK and also creates a client EC2 machine that has all software pre-installed so the customer can use the EC2 to run sam build and sam deploy commands to test out the lambda function very easily. Modified README.md accordingly

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


This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) CLI. It includes the following files and folders.

- HandlerKafka - Code for the application's Lambda function.
- events - Invocation events that you can use to invoke the function.
- template.yaml - An AWS SAM template that defines the application's AWS resources.
- template_original.yaml - An AWS SAM template that defines the application's AWS resources.
- MSKAndKafkaClientEC2.yaml - A Cloudformation template file that can be used to deploy an MSK cluster and also deploy an EC2 machine with all pre-requisities already installed, so you can directly build and deploy the lambda function and test it out.
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
- MSKAndKafkaClientEC2.yaml - A Cloudformation template file that can be used to deploy an MSK cluster and also deploy an EC2 machine with all pre-requisities already installed, so you can directly build and deploy the lambda function and test it out.
- MSKAndKafkaClientEC2.yaml - An AWS CloudFormation template file that can be used to deploy an MSK cluster and also deploy an Amazon EC2 instance with all prerequisites already installed, so you can directly build and deploy the Lambda function and test it out.

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated


## Deploy the sample application
## Run the Cloudformation template to create the MSK Cluster and Client EC2 machine
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
## Run the Cloudformation template to create the MSK Cluster and Client EC2 machine
## Deploy the CloudFormation template to create the MSK cluster and client EC2 instance

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated


The AWS SAM CLI is a serverless tool for building and testing Lambda applications. It uses Docker to locally test your functions in an Amazon Linux environment that resembles the Lambda execution environment. It can also emulate your application's build environment and API.
* [Run the Cloudformation template using the file MSKAndKafkaClientEC2.yaml] - You can go to the AWS Cloudformation console, create a new stack by specifying the template file. You can keep the defaults for input parameters or modify them as necessary. Wait for the Cloudformation stack to be created. This Cloudformation template will create an MSK cluster (Provisioned or Serverless based on your selection). It will also create an EC2 machine that you can use as a client.
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
* [Run the Cloudformation template using the file MSKAndKafkaClientEC2.yaml] - You can go to the AWS Cloudformation console, create a new stack by specifying the template file. You can keep the defaults for input parameters or modify them as necessary. Wait for the Cloudformation stack to be created. This Cloudformation template will create an MSK cluster (Provisioned or Serverless based on your selection). It will also create an EC2 machine that you can use as a client.
* [Deploy the CloudFormation template using the file MSKAndKafkaClientEC2.yaml] - You can go to the AWS CloudFormation console, create a new stack by specifying the template file. You can keep the defaults for input parameters or modify them as necessary. Wait for the CloudFormation stack to be created. This CloudFormation template will create an MSK cluster (Provisioned or Serverless based on your selection). It will also create an EC2 instance that you can use as a client.

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated

The AWS SAM CLI is a serverless tool for building and testing Lambda applications. It uses Docker to locally test your functions in an Amazon Linux environment that resembles the Lambda execution environment. It can also emulate your application's build environment and API.
* [Run the Cloudformation template using the file MSKAndKafkaClientEC2.yaml] - You can go to the AWS Cloudformation console, create a new stack by specifying the template file. You can keep the defaults for input parameters or modify them as necessary. Wait for the Cloudformation stack to be created. This Cloudformation template will create an MSK cluster (Provisioned or Serverless based on your selection). It will also create an EC2 machine that you can use as a client.

* [Connect to the EC2 machine] - Once the Cloudformation stack is created, you can go to the EC2 console and log into the machine using either "Connect using EC2 Instance Connect" or "Connect using EC2 Instance Connect Endpoint" option under the "EC2 Instance Connect" tab.
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
* [Connect to the EC2 machine] - Once the Cloudformation stack is created, you can go to the EC2 console and log into the machine using either "Connect using EC2 Instance Connect" or "Connect using EC2 Instance Connect Endpoint" option under the "EC2 Instance Connect" tab.
* [Connect to the EC2 instance] - Once the CloudFormation stack is created, you can go to the EC2 console and log into the instance using either "Connect using EC2 Instance Connect" or "Connect using EC2 Instance Connect Endpoint" option under the "EC2 Instance Connect" tab.

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated

* [Run the Cloudformation template using the file MSKAndKafkaClientEC2.yaml] - You can go to the AWS Cloudformation console, create a new stack by specifying the template file. You can keep the defaults for input parameters or modify them as necessary. Wait for the Cloudformation stack to be created. This Cloudformation template will create an MSK cluster (Provisioned or Serverless based on your selection). It will also create an EC2 machine that you can use as a client.

* [Connect to the EC2 machine] - Once the Cloudformation stack is created, you can go to the EC2 console and log into the machine using either "Connect using EC2 Instance Connect" or "Connect using EC2 Instance Connect Endpoint" option under the "EC2 Instance Connect" tab.
Note: You may need to wait for some time after the Cloudformation stack is created, as some UserData scripts continue running after the Cloudformation stack shows Created.
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
Note: You may need to wait for some time after the Cloudformation stack is created, as some UserData scripts continue running after the Cloudformation stack shows Created.
Note: You may need to wait for some time after the CloudFormation stack is created, as some UserData scripts continue running after the CloudFormation stack shows Created.

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated

REPORT RequestId: 2d1041e7-fb49-4181-a8ac-15277f5d2b6c Init Duration: 11.37 msDuration: 2696.60 ms Billed Duration: 2697 ms Memory Size: 128 MB Max Memory Used: 128 MB
```
confirm by pressing y for both the questions
You should see the lambda function getting deleted and a final confirmation "Deleted successfully" on the command-line
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
You should see the lambda function getting deleted and a final confirmation "Deleted successfully" on the command-line
You should see the Lambda function getting deleted and a final confirmation "Deleted successfully" on the command line

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated

```bash
sam delete
```
Next you need to delete the Cloudformation template that created the MSK Server and the EC2 machine by going to the Cloudformation console and selecting the stack and then hitting the "Delete" button. It will run for sometime but eventually you should see the stack getting cleaned up.
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
Next you need to delete the Cloudformation template that created the MSK Server and the EC2 machine by going to the Cloudformation console and selecting the stack and then hitting the "Delete" button. It will run for sometime but eventually you should see the stack getting cleaned up.
Next, you delete the CloudFormation template that created the MSK cluster and the EC2 instance by going to the CloudFormation console and selecting the stack. Then select the "Delete" button. Please note that it might take a while to complete.

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated


* **Parameter MSKClusterId**: The unique ID of the MSKCluster, eg. a4e132c8-6ad0-4334-a313-123456789012-s2
* **Parameter MSKClusterName**: The name of the MSKCluster
* **Parameter MSKClusterId**: The unique ID of the MSKCluster
* **Parameter MSKTopic**: The Kafka topic on which the lambda function will listen on
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
* **Parameter MSKTopic**: The Kafka topic on which the lambda function will listen on
* **Parameter MSKTopic**: The Kafka topic on which the Lambda function will listen on

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated


This project contains source code and supporting files for a serverless application that you can deploy with the AWS Serverless Application Model (AWS SAM) CLI. It includes the following files and folders.

- HandlerKafka - Code for the application's Lambda function.
- events - Invocation events that you can use to invoke the function.
- template.yaml - An AWS SAM template that defines the application's AWS resources.
- template_original.yaml - An AWS SAM template that defines the application's AWS resources.
- MSKAndKafkaClientEC2.yaml - A Cloudformation template file that can be used to deploy an MSK cluster and also deploy an EC2 machine with all pre-requisities already installed, so you can directly build and deploy the lambda function and test it out.
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
- MSKAndKafkaClientEC2.yaml - A Cloudformation template file that can be used to deploy an MSK cluster and also deploy an EC2 machine with all pre-requisities already installed, so you can directly build and deploy the lambda function and test it out.
- MSKAndKafkaClientEC2.yaml - A CloudFormation template file that can be used to deploy an MSK cluster and also deploy an EC2 instance with all prerequisites already installed, so you can directly build and deploy the Lambda function and test it out.

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated

sam build
sam deploy --guided
```
## Run the Cloudformation template to create the MSK Cluster and Client EC2 machine
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not going to mark every instance, but please double check the correct spelling:
Cloudformation -> CloudFormation
lambda -> Lambda
EC2 machine -> EC2 instance

Choose a reason for hiding this comment

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

Checked in modified Readme.md files with changes incorporated

…m and msk-lambda-iam-python-sam to include retry mechanism for all yum install commands
…a-iam-python-sam based on review feedback from Ben Freiberg
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason why you renamed the file?

Choose a reason for hiding this comment

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

template_original.yaml file has variables for input parameters. In the Cloudformation template, I copy this file to template.yaml and then replace the variables with correct values for input variables such as MSK brokers, topic etc.

@bfreiberg
Copy link
Contributor

Looks good. Ready to merge once the file renaming is sorted out

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.

5 participants