Giter Club home page Giter Club logo

blobcopybetweenstorageaccount's Introduction

Copy Blobs using a Service Bus Queue Mediator

These Azure Functions copy files between storage accounts using a Service Bus queue as a mediator. Some traceability and features are included:

  • Tracking correlationID from submission of the JSON Request to CosmosDB to finally the Blob's metadata in the copied Storage Account
  • Tracking the Source of the reuquest in CosmosDB as well as Blob Metadata
  • Cosmos DB is configured to partition by CustomerID, allowing efficient queries by customer

Resources required

You can use the Azure CLI script (resources.azcli) in the IaC folder to deploy these resources via Azure CLI

  1. Storage Account for Azure Functions: jpodefault
  2. Origin Blob Storage:
    • Storage Account for origin blobs: jpovirginia
    • Container within this storage account for incoming blobs: inbox
    • Container within this storage account for outgoing blobs: outbox
  3. Destination Blob Storage
    • Storage account for destination blobs: jpoarizona
    • Container within this storage account for incoming blobs: inbox
    • Container within this storage account for outgoing blobs: outbox
  4. Destination Blob Storage
    • Storage account for destination blobs: jpoiowa
    • Container within this storage account for incoming blobs: inbox
    • Container within this storage account for outgoing blobs: outbox
  5. Service Bus Namespace: jposervicebus
    • Topic: all_files
    • Subscription within this topic: mysub
  6. Cosmos DB Account
    • Database name: jpo
    • Collection Name: logdb

Payload

The payload for the message is a JSON file that provides the following controls:

    public class JPOFileInfo {
        public string source { get; set; } = "";  //Source Container Name
        public string destination { get; set; } = ""; //Destination Container name
        public string tags { get; set; } = "";
        public string origin { get; set; } = "";
        public string fileName { get; set; } = "";
        public DateTime date { get; set; } = DateTime.Now;
        public string description { get; set; } = "";
        public string correlationID { get; set; } = "";
        public string customerID { get; set; } = "";
    }

The tags can be used for managing flow. The JSON payload looks like:

"{"source":"outbox","destination":"inbox","tags":"tag1, tag2, tag3","origin":"Elvis","fileName":"win10-vs.rdp","date":"2021-03-17T09:55:46.9883908-04:00","description":"Return to sender"}"

localsettings.json

Edit this localsettings.json file to replace your own. Replace <YOUR_KEY_HERE> with values from your deployed resources.

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=jpodefault;AccountKey=;EndpointSuffix=core.usgovcloudapi.net", //DefaultEndpointsProtocol=https;AccountName=rcdev1;AccountKey=kaqcWkmMv+51mwlw19bnhu4+a7rk5YnzwcXHqvG1ambF3mF6jkzRQwUbvihoPh7+WL1p5V6YE15DoCKyk86IgQ==;BlobEndpoint=https://rcdev1.blob.core.windows.net/;TableEndpoint=https://rcdev1.table.core.windows.net/;QueueEndpoint=https://rcdev1.queue.core.windows.net/;FileEndpoint=https://rcdev1.file.core.windows.net/",
    "AccountMonitored": "DefaultEndpointsProtocol=https;AccountName=jpovirginia;AccountKey=;EndpointSuffix=core.usgovcloudapi.net",
    "JPOServiceBus": "Endpoint=sb://jposervicebus.servicebus.usgovcloudapi.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey",
    "receive_topic": "Endpoint=sb://jposervicebus.servicebus.usgovcloudapi.net/;SharedAccessKeyName=receive;SharedAccessKey=",
    "jpovirginia": "DefaultEndpointsProtocol=https;AccountName=jpovirginia;AccountKey=;EndpointSuffix=core.usgovcloudapi.net",
    "jpoarizona": "DefaultEndpointsProtocol=https;AccountName=jpoarizona;AccountKey=;EndpointSuffix=core.usgovcloudapi.net",
    "jpoiowa": "DefaultEndpointsProtocol=https;AccountName=jpoiowa;AccountKey=;EndpointSuffix=core.usgovcloudapi.net",
    "cosmosdb_log": "AccountEndpoint=",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "outgoing_container": "outbox/",
    "incoming_container": "inbox/",
    "version": "0.2"
  }
}

How to test

Once running either locally or in Azure:

  1. Upload one or more blobs to the inbox Container in any of the Storage Accounts
  2. Use Postman or another tool configure a PUT request to the URL for the MakeItSo Function, and add the following JSON Payload:
{
	"source":"jpoiowa",
	"destination":"jpovirginia",
	"tags":"tag1, tag2, tag3",
	"fileName":"Hello World - 3.txt",
	"date":"2021-03-17T09:55:46.9883908-04:00",
	"description":"file transfer",
	"customerID":"1"
}

  1. Modify the source and destination here to be one of the values in the local.settings.json file (here it is jpovirginia, jpoarizona or jpoiowa)
  2. Send the Put request
  3. See that the file from the inbox container of the source storage account has been moved to the outbox container of the destination storage account
  4. See that the tags have been appended to the blobs's metadata.
  5. See that the blob metadata contains the 'source' tag
  6. See that the corrlationID returned by the MakeItSo Function matches logs in Cosmos DB as well as the related Blob Metadata

Screenshots

Flow

alt text

HTTP Put Request with JSON payload sent via Postman

The client here is Postman, but it could be any app that can make an HTTPS PUT Request with a JSON Payload alt text

Storage Account

alt text

Blob Metadata

The metadata for the copied blob is set with the Tags specified in the JSON Request, as well as the Source and Description passed. alt text

Storage Account

This Power BI Dashboard is built off live-time Cosmos DB data. alt text

blobcopybetweenstorageaccount's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.