Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0ee0269
F# Blob Storage documentation
sylvanc Sep 21, 2016
35bfd81
F# Queue Storage documentation
sylvanc Sep 21, 2016
014642f
Update queue-storage.md
dsyme Sep 21, 2016
ee882f1
table storage WIP
sylvanc Sep 22, 2016
d342253
Update table-storage.md
sylvanc Sep 22, 2016
0a863bd
Update table-storage.md
dsyme Sep 22, 2016
5b90766
Various updates to make the walkthrough run more smoothly
dsyme Sep 22, 2016
59b95c8
Update blob-storage.md
dsyme Sep 22, 2016
fd017c0
Merge pull request #1 from sylvanc/dsyme-patch-1
dsyme Sep 22, 2016
7ab6426
Add file-storage.md
sylvanc Sep 22, 2016
1b9e7f0
Merge branch 'feature/fsharp-azure' of https://github.com/sylvanc/cor…
sylvanc Sep 22, 2016
a1532e0
Write a small landing page
dsyme Sep 22, 2016
776e263
Update index.md
dsyme Sep 22, 2016
ac9d192
Merge pull request #2 from sylvanc/dsyme-patch-2
dsyme Sep 22, 2016
f25a2a1
Remove uses of Console.WriteLine
dsyme Sep 22, 2016
47444f1
Merge pull request #3 from sylvanc/dsyme-patch-3
dsyme Sep 22, 2016
a64909c
Update index.md
dsyme Sep 22, 2016
31c2dc1
Update blob storage to use script samples.
cartermp Sep 22, 2016
e73861e
Update file storage to use script samples.
cartermp Sep 22, 2016
0f8fe48
Update queue storage to use script samples.
cartermp Sep 22, 2016
fa37985
Update table storage to use script samples.
cartermp Sep 22, 2016
a4e176b
Adjust NOTE
cartermp Sep 22, 2016
a3fef40
Merge pull request #4 from sylvanc/phcart/update-1
sylvanc Sep 26, 2016
9352d06
Fix relative path to .fsx snippets
sylvanc Sep 26, 2016
6f9069a
Fix Open Publishing warnings and errors
sylvanc Sep 26, 2016
43c49a7
Add articles to TOC
cartermp Sep 26, 2016
5f29de0
Fix code snippet references
cartermp Sep 26, 2016
4e55877
Incorporate comments from @mairaw
sylvanc Sep 27, 2016
423aa1b
Merge branch 'feature/fsharp-azure' of https://github.com/sylvanc/cor…
sylvanc Sep 27, 2016
b24c220
Adding a small section on Virtual Machines and F#
dsyme Sep 28, 2016
a13ea7a
Incorporate comments from @mairaw and @badersur
sylvanc Sep 28, 2016
2023392
Add information on Azure Functions
dsyme Sep 28, 2016
5356a25
fix minor typos
sylvanc Sep 28, 2016
5aae493
Add info on Event Hubs and DocumentDB
dsyme Sep 28, 2016
ff550ba
Add some more Azure use cases covered by F# for Azure Functions
dsyme Sep 28, 2016
390161c
Add notes about provisioning
dsyme Sep 28, 2016
a532c14
Update index.md
dsyme Sep 28, 2016
87b0f07
Update index.md
dsyme Sep 28, 2016
a86736d
Update index.md
dsyme Sep 28, 2016
6a15ef6
file share names must be lower case
dsyme Sep 29, 2016
0ac5a6a
Update file-storage.fsx
dsyme Sep 29, 2016
4b1d831
Update file-storage.fsx
dsyme Sep 29, 2016
7e8a641
Update file-storage.fsx
dsyme Sep 29, 2016
074b8e2
Adjust file storage to show upload of file
dsyme Sep 29, 2016
b3274f6
Adjust references to script
dsyme Sep 29, 2016
a1237c5
Update queue-storage.fsx
dsyme Sep 29, 2016
9e3d508
Update queue-storage.md
dsyme Sep 29, 2016
e3b0c86
Updates to make tables script run end-to-end
dsyme Sep 29, 2016
10a1cae
Update table-storage.fsx
dsyme Sep 29, 2016
55b7843
Update blob-storage.fsx
dsyme Sep 29, 2016
e6bc931
Update file-storage.fsx
dsyme Sep 29, 2016
d8cde3c
Update queue-storage.fsx
dsyme Sep 29, 2016
4c986ae
Update blob-storage.md
dsyme Sep 29, 2016
cb7b77b
Update file-storage.md
dsyme Sep 29, 2016
e75e8ca
Update blob-storage.fsx
dsyme Sep 29, 2016
cd85cc6
Update index.md
dsyme Sep 29, 2016
5d05fc0
Update table-storage.fsx
dsyme Sep 29, 2016
21b3b30
Update table-storage.md
dsyme Sep 29, 2016
68488da
Update table-storage.md
dsyme Sep 29, 2016
ceb9747
Update index.md
dsyme Sep 29, 2016
7e3e03e
Minor updates
dsyme Sep 30, 2016
2bef36e
Update index.md
dsyme Sep 30, 2016
4bf9821
updates from review
dsyme Oct 7, 2016
4eeeb20
Merge branch 'master' of https://github.com/dotnet/core-docs into fea…
dsyme Oct 10, 2016
d1df815
Fix link?
cartermp Oct 11, 2016
b146499
Fix header
cartermp Oct 11, 2016
21eb23c
Link package management doc into TOC
cartermp Oct 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 253 additions & 0 deletions docs/fsharp/using-fsharp-on-azure/blob-storage.md

Large diffs are not rendered by default.

161 changes: 161 additions & 0 deletions docs/fsharp/using-fsharp-on-azure/file-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
---
title: Get started with Azure File storage using F#
description: Store file data in the cloud with Azure File storage, and mount your cloud file share from an Azure virtual machine (VM) or from an on-premises application running Windows.
keywords: visual f#, f#, functional programming, .NET, .NET Core, Azure
author: sylvanc
manager: jbronsk
ms.date: 09/20/2016
ms.topic: article
ms.prod: visual-studio-dev14
ms.technology: devlang-fsharp
ms.devlang: dotnet
ms.assetid: 5c26a0aa-186e-476c-9f87-e0191754579e
---

# Get started with Azure File storage using F# #

Azure File storage is a service that offers file shares in the cloud using the standard [Server Message Block (SMB) Protocol](https://msdn.microsoft.com/library/windows/desktop/aa365233.aspx). Both SMB 2.1 and SMB 3.0 are supported. With Azure File storage, you can migrate legacy applications that rely on file shares to Azure quickly and without costly rewrites. Applications running in Azure virtual machines or cloud services or from on-premises clients can mount a file share in the cloud, just as a desktop application mounts a typical SMB share. Any number of application components can then mount and access the File storage share simultaneously.

For a conceptual overview of file storage, please see [the .NET guide for file storage](https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-files/).

## Prerequisites

To use this guide, you must first [create an Azure storage account](https://azure.microsoft.com/en-us/documentation/articles/storage-create-storage-account/).
You'll also need your storage access key for this account.

## Create an F# Script and Start F# Interactive

The samples in this article can be used in either an F# application or an F# script. To create an F# script, create a file with the `.fsx` extension, for example `files.fsx`, in your F# development environment.

Next, use a [package manager](package-management.md) such as [Paket](https://fsprojects.github.io/Paket/) or [NuGet](https://www.nuget.org/) to install the `WindowsAzure.Storage` package and reference `WindowsAzure.Storage.dll` in your script using a `#r` directive.

### Add namespace declarations

Add the following `open` statements to the top of the `files.fsx` file:

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L1-L5)]

### Get your connection string

You'll need an Azure Storage connection string for this tutorial. For more information about connection strings, see [Configure Storage Connection Strings](https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/).

For the tutorial, you'll enter your connection string in your script, like this:

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L11-L11)]

However, this is **not recommended** for real projects. Your storage account key is similar to the root password for your storage account. Always be careful to protect your storage account key. Avoid distributing it to other users, hard-coding it, or saving it in a plain-text file that is accessible to others. You can regenerate your key using the Azure Portal if you believe it may have been compromised.

For real applications, the best way to maintain your storage connection string is in a configuration file. To fetch the connection string from a configuration file, you can do this:

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L13-L15)]

Using Azure Configuration Manager is optional. You can also use an API such as the .NET Framework's `ConfigurationManager` type.

### Parse the connection string

To parse the connection string, use:

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L21-L22)]

This will return a `CloudStorageAccount`.

### Create the File service client

The `CloudFileClient` type enables you to programmatically use files stored in File storage. Here's one way to create the service client:

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L28-L28)]

Now you are ready to write code that reads data from and writes data to File storage.

## Create a file share

This example shows how to create a file share if it does not already exist:

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L34-L35)]

## Create a root directory and a subdirectory

Here, you get the root directory and get a sub-directory of the root. You create both if they don't already exist.

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L41-L43)]

## Upload text as a file

This example shows how to upload text as a file.

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L49-L50)]

### Download a file to a local copy of the file

Here you download the file just created, appending the contents to a local file.

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L56-L56)]

### Set the maximum size for a file share

The example below shows how to check the current usage for a share and how to set the quota for the share. `FetchAttributes` must be called to populate a share's `Properties`, and `SetProperties` to propagate local changes to Azure File storage.
Copy link
Contributor

Choose a reason for hiding this comment

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

example below -> following example


[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L62-L72)]

### Generate a shared access signature for a file or file share

You can generate a shared access signature (SAS) for a file share or for an individual file. You can also create a shared access policy on a file share to manage shared access signatures. Creating a shared access policy is recommended, as it provides a means of revoking the SAS if it should be compromised.

Here, you create a shared access policy on a share, and then use that policy to provide the constraints for a SAS on a file in the share.

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L78-L94)]

For more information about creating and using shared access signatures, see [Using Shared Access Signatures (SAS)](https://azure.microsoft.com/en-gb/documentation/articles/storage-dotnet-shared-access-signature-part-1/) and [Create and use a SAS with Blob storage](https://azure.microsoft.com/en-gb/documentation/articles/storage-dotnet-shared-access-signature-part-2/).

### Copy files

You can copy a file to another file or to a blob, or a blob to a file. If you are copying a blob to a file, or a file to a blob, you *must* use a shared access signature (SAS) to authenticate the source object, even if you are copying within the same storage account.

### Copy a file to another file

Here, you copy a file to another file in the same share. Because this copy operation copies between files in the same storage account, you can use Shared Key authentication to perform the copy.

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L100-L101)]

### Copy a file to a blob

Here, you create a file and copy it to a blob within the same storage account. You create a SAS for the source file, which the service uses to authenticate access to the source file during the copy operation.

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L107-L120)]

You can copy a blob to a file in the same way. If the source object is a blob, then create a SAS to authenticate access to that blob during the copy operation.

## Troubleshooting File storage using metrics

Azure Storage Analytics supports metrics for File storage. With metrics data, you can trace requests and diagnose issues.

You can enable metrics for File storage from the [Azure Portal](https://portal.azure.com), or you can do it from F# like this:

[!code-fsharp[FileStorage](../../../samples/snippets/fsharp/azure/file-storage.fsx#L126-L140)]

## Next steps

See these links for more information about Azure File storage.

### Conceptual articles and videos

- [Azure Files Storage: a frictionless cloud SMB file system for Windows and Linux](https://azure.microsoft.com/documentation/videos/azurecon-2015-azure-files-storage-a-frictionless-cloud-smb-file-system-for-windows-and-linux/)
- [How to use Azure File Storage with Linux](https://azure.microsoft.com/en-gb/documentation/articles/storage-how-to-use-files-linux/)

### Tooling support for File storage

- [Using Azure PowerShell with Azure Storage](https://azure.microsoft.com/en-gb/documentation/articles/storage-powershell-guide-full/)
- [How to use AzCopy with Microsoft Azure Storage](https://azure.microsoft.com/en-gb/documentation/articles/storage-use-azcopy/)
- [Using the Azure CLI with Azure Storage](https://azure.microsoft.com/en-gb/documentation/articles/storage-azure-cli/#create-and-manage-file-shares)

### Reference

- [Storage Client Library for .NET reference](https://msdn.microsoft.com/library/azure/mt347887.aspx)
- [File Service REST API reference](http://msdn.microsoft.com/library/azure/dn167006.aspx)

### Blog posts

- [Azure File storage is now generally available](https://azure.microsoft.com/blog/azure-file-storage-now-generally-available/)
- [Inside Azure File Storage](https://azure.microsoft.com/blog/inside-azure-file-storage/)
- [Introducing Microsoft Azure File Service](http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/12/introducing-microsoft-azure-file-service.aspx)
- [Persisting connections to Microsoft Azure Files](http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/27/persisting-connections-to-microsoft-azure-files.aspx)
102 changes: 101 additions & 1 deletion docs/fsharp/using-fsharp-on-azure/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,104 @@
---
title: Using F# on Azure
description: Guide to using Azure services with F#
keywords: Azure, cloud, visual f#, f#, functional programming, .NET, .NET Core
author: sylvanc
manager: jbronsk
ms.date: 09/22/2016
ms.topic: article
ms.prod: .net-core
ms.technology: .net-core-technologies
ms.devlang: dotnet
ms.assetid: FAD4D11E-703A-42D4-9F72-893D9E0F569B
---


# Using F# on Azure

F# is a superb language for cloud programming and is frequently used to write web applications, cloud services, cloud-hosted microservices, and for scalable data processing.

In the following sections, you will find resources on how to use a range of Azure services with F#.

> [!NOTE]
This is still in progress.
> If a particular Azure service isn't in this documentation set, please consult either the Azure Functions or .NET documentation for that service. Some Azure services are language-independent and require no language-specific documentation and are not listed here.

## Using Azure Virtual Machines with F# #

Azure supports a wide range of virtual machine (VM) configurations, see [Linux and Azure Virtual Machines](https://azure.microsoft.com/en-us/services/virtual-machines/).

To install F# on a virtual machine for execution, compilation and/or scripting see [Using F# on Linux](http://fsharp.org/use/linux) and [Using F# on Windows](http://fsharp.org/use/windows).


## Using Azure Functions with F# #

[Azure Functions](https://azure.microsoft.com/en-us/services/functions/) is a solution for easily running small pieces of code, or "functions," in the cloud. You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it. Your functions are connected to events in Azure storage and other cloud-hosted resources. Data flows into your F# functions via function arguments. You can use your development language of choice, trusting Azure to scale as needed.

Azure Functions support F# as a first-class language with efficient, reactive, scalable execution of F# code. See the [Azure Functions F# Developer Reference](https://azure.microsoft.com/en-us/documentation/articles/functions-reference-fsharp/) for reference documentation on how to use F# with Azure Functions.

Other resources for using Azure Functions and F#:

* [Scale Up Azure Functions in F# Using Suave](http://blog.tamizhvendan.in/blog/2016/09/19/scale-up-azure-functions-in-f-number-using-suave/)

## Using Azure Storage with F# #

Azure Storage is a base layer of storage services for modern applications that rely on durability, availability, and scalability to meet the needs of customers. F# programs can interact directly with Azure storage services, using the techinques described in the following articles.

* [Get started with Azure Blob storage using F#](blob-storage.md)
* [Get started with Azure File storage using F#](file-storage.md)
* [Get started with Azure Queue storage using F#](queue-storage.md)
* [Get started with Azure Table storage using F#](table-storage.md)

Azure Storage can also be used in conjunction with Azure Functions through declarative configuration rather than explicit API calls. See [Azure Functions triggers and bindings for Azure Storage](https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-storage/) which includes F# examples.


## Using Azure DocumentDB with F# #

[Azure DocumentDB](https://azure.microsoft.com/en-us/services/documentdb/) is a NoSQL service for highly available, globally distributed apps.

Azure DocumentDB can be used with F# in two ways:

1. Through the creation of F# Azure Functions which react to or cause changes to DocumentDB collections. See [Azure Function triggers for DocumentDB](https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-documentdb/), or
2. By using the [.NET SDK for Azure](https://azure.microsoft.com/en-us/documentation/articles/documentdb-get-started-quickstart/). Note these examples are in C#.

## Using Azure Event Hubs with F# #

[Azure Event Hubs](https://azure.microsoft.com/en-us/services/event-hubs/) provide cloud-scale telemetry ingestion from websites, apps, and devices.

Azure Event Hubs can be used with F# in two ways:

1. Through the creation of F# Azure Functions which are triggered by events. See [Azure Function triggers for Event Hubs](https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-event-hubs/), or
2. By using the [.NET SDK for Azure](https://azure.microsoft.com/en-us/documentation/articles/event-hubs-csharp-ephcs-getstarted/). Note these examples are in C#.

## Using Azure Notifcation Hubs with F# #

[Azure Notification Hubs](https://azure.microsoft.com/en-us/documentation/services/notification-hubs/) are multiplatform, scaled-out push infrastructure that enable you to send mobile push notifications from any backend (in the cloud or on-premises) to any mobile platform.

Azure Notification Hubs can be used with F# in two ways:

1. Through the creation of F# Azure Functions which send results to a notification hub. See [Azure Function output triggers for Notification Hubs](https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-notification-hubs/), or
2. By using the [.NET SDK for Azure](https://blogs.msdn.microsoft.com/azuremobile/2014/04/08/push-notifications-using-notification-hub-and-net-backend/). Note these examples are in C#.


## Implementing WebHooks on Azure with F# #

A [Webhook](https://en.wikipedia.org/wiki/Webhook) is a callback triggered via a web request. Webhooks are used by sites such as GitHub to signal events.

Webhooks can be implemented in F# and hosted on Azure via an [Azure Function in F# with a Webhook Binding](https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-http-webhook/).

## Implementing Timers on Azure with F# #

Timer triggers call functions based on a schedule, one time or recurring.

Timers can be implemented in F# and hosted on Azure via an [Azure Function in F# with a Timer Trigger](https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-timer/).

## Deploying and Managing Azure Resources with F# Scripts #

Azure VMs may be programmatically deployed and managed from F# scripts by using the Microsoft.Azure.Management packages and APIs. For example, see [Get Started with the Management Libraries for .NET](https://msdn.microsoft.com/en-us/library/dn722415.aspx) and [Using Azure Resource Manager](https://azure.microsoft.com/en-us/documentation/articles/resource-manager-deployment-model/).

Likewise, other Azure resources may also be deployed and managed from F# scripts using the same components. For example, you can create storage accounts, deploy Azure Cloud Services, create Azure DocumentDB instances and manage Azure Notifcation Hubs programmatically from F# scripts.

Using F# scripts to deploy and manage resources is not normally necessary. For example, Azure resources may also be deployed directy from JSON template descriptions, which can be parameterized. See [Azure Resource Manager Templates](https://azure.microsoft.com/en-us/documentation/articles/resource-manager-template-best-practices/) including examples such as the [Azure Quickstart Templates](https://azure.microsoft.com/en-us/documentation/templates/).

## Other resources

* [Full documentation on all Azure services](https://azure.microsoft.com/en-us/documentation/)
Loading