{"id":15577497,"url":"https://github.com/shanepeckham/openfaascosmos","last_synced_at":"2026-04-30T00:03:11.015Z","repository":{"id":69130257,"uuid":"121835282","full_name":"shanepeckham/openfaascosmos","owner":"shanepeckham","description":"Openfaas function to query Azure CosmosDB","archived":false,"fork":false,"pushed_at":"2018-03-02T09:53:44.000Z","size":155,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T07:27:55.445Z","etag":null,"topics":["aks","azure","containers","cosmosdb","openfaas","openfaas-function","serverless"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shanepeckham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-17T07:13:04.000Z","updated_at":"2018-02-19T23:04:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d230af4-9a6d-425a-a42d-7d07be53320e","html_url":"https://github.com/shanepeckham/openfaascosmos","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shanepeckham/openfaascosmos","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanepeckham%2Fopenfaascosmos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanepeckham%2Fopenfaascosmos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanepeckham%2Fopenfaascosmos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanepeckham%2Fopenfaascosmos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shanepeckham","download_url":"https://codeload.github.com/shanepeckham/openfaascosmos/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanepeckham%2Fopenfaascosmos/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32448883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aks","azure","containers","cosmosdb","openfaas","openfaas-function","serverless"],"created_at":"2024-10-02T19:01:22.481Z","updated_at":"2026-04-30T00:03:10.988Z","avatar_url":"https://github.com/shanepeckham.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deploying a function to OpenFaas \n\n## Install the FaaS CLI\n\nInstall the [FaaS CLI](https://github.com/openfaas/faas-cli) so that you can deploy your functions quickly.\n\n##  Provisioning a CosmosDB instance\n\nWe will deploy a Golang function that will connect to Azure CosmosDB and query records from a collection. First we need to set up an Azure CosmosDB instance.\n\nLet's start by creating a Cosmos DB instance. We will use the [Azure CLI 2.0](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) to provision a CosmosDB account.\n\nIn the following command, please substitute your own unique Azure Cosmos DB account name where you see the `\u003ccosmosdb-name\u003e` placeholder. This unique name will be used as part of your Azure Cosmos DB endpoint ```https://\u003ccosmosdb-name\u003e.documents.azure.com/```, so the name needs to be unique across all Azure Cosmos DB accounts in Azure.\n\n```\naz cosmosdb create --name \u003ccosmosdb-name\u003e --resource-group myResourceGroup --kind MongoDB\n```\n\nOnce the DB is provisioned, we need to get the Connection String, this may be found in the Settings --\u003e Connection Strings section of your DB. We will need this to run our pre-built Golang container, so copy it for convenient access. See below:\n\n![alt text](https://github.com/shanepeckham/ContainersOnAzure_IntroLab/blob/master/images/CosmosConnString.png)\n\n## Load sample data into a collection in CosmosDB\n\nData stored by an Azure Cosmos DB is available to view, query, and run business-logic on in the Azure portal. For simplicity we will create a Database, Collection and Documents in the Azure portal.\n\nTo view, query, and work with the user data created in the previous step, login to the [Azure portal](https://portal.azure.com) in your web browser.\n\nIn the top Search box, type Azure Cosmos DB. When your Cosmos DB account blade opens, select your Cosmos DB account. In the left navigation, click Data Explorer.\n\nWe will create a new Database and Collection, both called 'plans'. In the Data Explorer, select New Collection and enter the following values:\n\n* Database Id: plans\n* Collection Id: plans\n* Storage Capacity: Fixed (10Gb)\n* Throughput: 500\n\n![alt text](https://github.com/shanepeckham/ContainersOnAzure_IntroLab/blob/master/images/NewCollection.png)\n\nSelect Ok.\n\nIn Data Explorer you should now see a Collection called plans, expand it so that you can see the Documents and select Documents. Select New Document and paste in the following JSON Document:\n\n```\n{\n\t\"name\" : \"two_person\",\n\t\"friendlyName\" : \"Two Person Plan\",\n\t\"portionSize\" : \"1-2 Person\",\n\t\"mealsPerWeek\" : \"3 Unique meals per week\",\n\t\"price\" : 72,\n\t\"description\" : \"Our basic plan, delivering 3 meals per week, which will feed 1-2 people.\",\n\t\"__v\" : 0\n}\n```\n\nSelect Save, CosmosDB will auto generate an Id for the Document. Now we can deploy our code to read this record.\n\n##  Deploying a function in OpenFaaS\n\nIn order to deploy our pre-built Golang container we will need values for the following variables:\n\n* OpenFaaS Gateway IP: This is the URL for your deployed OpenFaaS Gateway with AKS, it is the same as your OpenFaaS UI URL without the ui suffix, for example: ```http://127.0.0.1:8080```\n\n* image: For this example we will use our pre-built container which has been pushed to Docker Hub, namely ```shanepeckham/openfaascosmos```\n\n* Name: This is the name of your function, it can be anything\n\n* env: This is an environment variable which we will use to pass our CosmosDB connection string at runtime, we will not store the connection with code, ideally we would use a Kubernetes secret or inject this via Azure Key Vault. This will have the format ```--env=NODE_ENV=[CosmosDB Connection String]```\n\nWe will now use the faas-cli to deploy our pre-built Golang container to our OpenFaaS Gateway. To do so we need to run the following command:\n\n```\nfaas-cli deploy -g [OpenFaaS Gateway IP] --image=shanepeckham/openfaascosmos --name=[Your Function Name] --env=NODE_ENV=[CosmosDB Connection String]\n```\nSelect enter to deploy your function and you should see your newly created OpenFaaS endpoint for your function:\n\n```\nDeployed. 200 OK.\nURL: http://[OpenFaaS Gateway IP}/function/[Your Function Name]\n```\nNow you can test your function using curl:\n\n```\ncurl URL: http://[OpenFaaS Gateway IP}/function/[Your Function Name]\n```\nYou should see the following response:\n\n```\n[{\"ID\":\"87992b20-dcf3-1601-a4fa-908efb515024\",\"Name\":\"two_person\",\"FriendlyName\":\"\",\"PortionSize\":\"\",\"MealsPerWeek\":\"\",\"Price\":72,\"Description\":\"Our basic plan, delivering 3 meals per week, which will feed 1-2 people.\"}]\n```\n\nWe can also test our function within the OpenFaaS UI, see below:\n\n![alt text](https://github.com/shanepeckham/ContainersOnAzure_IntroLab/blob/master/images/OpenFaaSUI.png)\n\nYou have now successfully deployed a function to OpenFaaS and queried your plans Database and Collection in Azure CosmosDB!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshanepeckham%2Fopenfaascosmos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshanepeckham%2Fopenfaascosmos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshanepeckham%2Fopenfaascosmos/lists"}