Commit a9f0b83a authored by BH18294's avatar BH18294

Added README.md

parent f5feca23
......@@ -18,13 +18,20 @@
Service Account needs following permissions
roles/pubsub.publisher
* roles/pubsub.publisher
* roles/pubsub.subscriber
* roles/cloudfunctions.developer
* roles/logging.viewer
roles/pubsub.subscriber
# Deployment steps:
roles/cloudfunctions.developer
## Create an API key:
roles/logging.viewer
* Sign in to SendGrid and go to Settings > API Keys.
* Create an API key.
* Select the permissions for the key. At a minimum, the key must have Mail send permissions to send email.
* Click Save to create the key.
* SendGrid generates a new key. This is the only copy of the key, so make sure that you copy the key and save it for later.
**Deployment steps: **
......@@ -48,81 +55,81 @@
export PROJECT_ID=PROJECT_ID
Specify your Google Cloud organization in an environment variable.
* Specify your Google Cloud organization in an environment variable.
export ORG_ID=ORG_ID
Set the project ID for gcloud commands.
* Set the project ID for gcloud commands.
gcloud config set project PROJECT_ID
Create the Pub/Sub topic where notifications are published.
* Create the Pub/Sub topic where notifications are published.
gcloud pubsub topics create trigger-email
Specify the topic in an environment variable.
* Specify the topic in an environment variable.
export TOPIC=projects/$PROJECT_ID/topics/trigger-email
Create the subscription that notifies Cloud Functions to send an email or chat message when messages are published to the topic.
* Create the subscription that notifies Cloud Functions to send an email or chat message when messages are published to the topic.
gcloud pubsub subscriptions create gcf-trigger-email-asia-east2-trigger-email-sub --topic trigger-email
- Create SendGrid Email API account
## Create SendGrid Email API account
In this section, you create a SendGrid Email API account and obtain an API key. If you already have SendGrid enabled, skip to Obtain a Sendgrid Email API Key and ensure your existing API key has adequate permissions. Go to the Google Cloud console
In the search box at the top of the page, search for SendGrid Email API. SendGrid Search
* In the search box at the top of the page, search for SendGrid Email API. SendGrid Search
On the next page, select the plan that fits your needs.
* On the next page, select the plan that fits your needs.
Review the terms and if you're comfortable, click Subscribe.
* Review the terms and if you're comfortable, click Subscribe.
Activate the SendGrid service by clicking Register with SendGrid.
* Activate the SendGrid service by clicking Register with SendGrid.
On the registration screen, enter a username, password, and email address. Accept the terms of service and click Continue.
* On the registration screen, enter a username, password, and email address. Accept the terms of service and click Continue.
At the confirmation dialog, click Return to Google.
* At the confirmation dialog, click Return to Google.
- Obtain a SendGrid Email API key
## Obtain a SendGrid Email API key
Click Manage API keys on SendGrid website. A new tab opens for the SendGrid website. Manage API keys
Complete the form or sign in, if prompted. Then, click Get Started!
* Complete the form or sign in, if prompted. Then, click Get Started!
In the menu panel, expand Settings and click API Keys.
* In the menu panel, expand Settings and click API Keys.
On the next screen, click the Create API Key button.
* On the next screen, click the Create API Key button.
Under API Key Name, enter "Email Notifications," select Full Access, and then click the Create & View button.[Text Wrapping Break][Text Wrapping Break]API key name
* Under API Key Name, enter "Email Notifications," select Full Access, and then click the Create & View button.[Text Wrapping Break][Text Wrapping Break]API key name
You are shown the API key. Record the value. You need it in the next section.
* You are shown the API key. Record the value. You need it in the next section.
Click Done. You are shown the current set of API keys. Close the tab and return to the Google Cloud console.
* Click Done. You are shown the current set of API keys. Close the tab and return to the Google Cloud console.
Next, you deploy a Cloud Function to send notifications to an email address.
* Next, you deploy a Cloud Function to send notifications to an email address.
- Create the SendGrid Cloud Function
## Create the SendGrid Cloud Function
In this section, you deploy a function that sends notifications to your email account.
Ensure that you're using the same PROJECT_ID you used to create the Pub/Sub topic.
* Ensure that you're using the same PROJECT_ID you used to create the Pub/Sub topic.
Click Create Function. SendGrid function
* Click Create Function. SendGrid function
Set Function name to send-high-and-critical-finding-email-notification and the Trigger type to Pub/Sub.
* Set Function name to send-high-and-critical-finding-email-notification and the Trigger type to Pub/Sub.
Select the Pub/Sub topic that you created in Setting up a Pub/Sub topic.
* Select the Pub/Sub topic that you created in Setting up a Pub/Sub topic.
Click Save, and then click Next.
* Click Save, and then click Next.
On the next page, set Runtime to Python 3.10.
* On the next page, set Runtime to Python 3.10.
In the file list, click requirements.txt and add the following to the text field: sendgrid.[Text Wrapping Break][Text Wrapping Break]SendGrid requirements
* In the file list, click requirements.txt and add the following to the text field: sendgrid.[Text Wrapping Break][Text Wrapping Break]SendGrid requirements
Click main.py and replace the contents with your code snippet.
* Click main.py and replace the contents with your code snippet.
Navigate to the Entry point field and enter the name of the function in the code snippet (send_email_notification, in this example).
* Navigate to the Entry point field and enter the name of the function in the code snippet (send_email_notification, in this example).
Click Deploy. You are returned to the Cloud Functions list where you should see your new function. When a green check mark appears next to the function name, it has been successfully deployed. The process could take a few minutes.
\ No newline at end of file
* Click Deploy. You are returned to the Cloud Functions list where you should see your new function. When a green check mark appears next to the function name, it has been successfully deployed. The process could take a few minutes.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment