Skip to content

Demonstrates how to dynamically assign a SendGrid API key by using runtime binding.

License

Notifications You must be signed in to change notification settings

craigshoemaker/azure-functions-dynamic-sendgrid-api-key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Functions Dynamic SendGrid API Key

This project demonstrates how to dynamically assign a SendGrid API key by using runtime binding.

Setup

Clone this repository.

git clone https://github.com/craigshoemaker/azure-functions-dynamic-sendgrid-api-key.git

Open in Visual Studio Code:

code ./azure-functions-dynamic-sendgrid-api-key

Update local.settings.json

To run locally, you can use the following example local.settings.json. Be sure to swap out all placeholders for your values.

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "<AZURE_STORAGE_CONNECTION_STRING>",
        "SendGridAPIKey1": "<SENDGRID_API_KEY_1>",
        "SendGridAPIKey2": "<SENDGRID_API_KEY_2>",
        "EmailSender": "<SENDER_EMAIL_ADDRESS>",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

Run the function

The function accepts querystring parameters for:

  • the to email address
  • the associated SendGrid API key

Start debugging and send a request to the following URL. Make sure you update the querystring values with your desired values.

http://localhost:7071/api/SendMessage?to=person@test.com&key=SendGridAPIKey1

Note: The run.http file in the project works well with the REST Client Visual Studio Code extension.

Remarks

This project is meant for instructional purposes only.

In a production context, you likely do not want to pass the SendGrid API key name with the request. In the real world you would probably determine the API key by doing a look up based on the recipient's email address or pass in some other data to help determine the API key within the function.

About

Demonstrates how to dynamically assign a SendGrid API key by using runtime binding.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages