I’m often creating a new site that’s similar to others and has CloudFront in front of them (yes, think WordPress). Many of these distributions have a bunch of behaviors, and I hate to waste time trying to recreate them (copying and pasting, making sure I didn’t miss a step). Anyway, finally taking a little bit of time, I’ve found it’s straightforward to do it using the AWS CLI:
Steps to export, modify, and import a new CF config file with AWS cli:
- Install the CLI if you haven’t already. It’s relatively quick and straightforward, provided you have your access and secret keys. I’ve been using Version 2 of the CLI with great success. I’m primarily on Windows, so the below steps are respective of that.
- Using the CLI, export the CloudFront config of a distribution you want to copy. In my below example, you’ll need to swap out the distribution ID with one of your real distribution IDs (something like E3xxxxxxxxxx). Also, the c:\aws folder is whatever you want.
aws2 cloudfront get-distribution-config --id YourDistID --output json > c:\aws\sourceCFconfig.json
- Take this json file, sourceCFconfig.json, copy it to a new file, newCFconfig.json.
- Open the new file, edit out the first parent element (be sure to remove the last curly bracket at the end of the file as well).
- Edit the Aliases to reflect your new site info (or remove if you’re not doing HTTPS).
- If you’re using a different origin for this distribution, change that as well, including in the behaviors (make use of find and replace)!
- Near the end of the doc, change the comment to something new:
- Change the ViewerCertificate to a valid certificate ARN (or remove if you’re not using HTTPS).
- Save this file you’ve been editing.
- Import this config and create a new distribution using the below command:
aws2 cloudfront create-distribution --distribution-config file://c:\aws\newCFconfig.json
If no errors are shown, you should see a new distribution in CloudFront.
If you’re using Amazon Web Services RDS for SQL Server (btw, it works great) and want to use Memory-Optimized Objects, it’s easy to alter your DB to allow this. Below is a little T-SQL. The key to this is the directory “D:\rdsdbdata\“, the default where RDS is storing your data.
-- Add new file group
ALTER DATABASE [sampleDB] ADD FILEGROUP [MOD_FG] CONTAINS MEMORY_OPTIMIZED_DATA
-- Add the new file
ALTER DATABASE [sampleDB] ADD FILE ( NAME = N'Mem_Opt_Data', FILENAME = N'D:\rdsdbdata\DATA\Mem_Opt_Data.ndf') TO FILEGROUP [MOD_FG]
-- Set the MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT to On
ALTER DATABASE [sampleDB] SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT = ON
Things that you’ll need to swap out w/ your own info is “sampleDB” and “MOD_FG”.
Now your DB is all ready for some Memory-Optimized Objects.
Want to create a table that’s memory optimized, just use this:
-- Sample table create
CREATE TABLE testMOD (
SomeId INT IDENTITY(1,1)
,FirstName VARCHAR(30) NOT NULL
,LastName VARCHAR(30) NOT NULL
CONSTRAINT [PK_SomeID] PRIMARY KEY NONCLUSTERED HASH (SomeId) WITH (BUCKET_COUNT = 131072))
WITH(MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA)
These Memory-Optimized Objects do offer a significant speed improvement but don’t go crazy w/ them.
Creating a simple, serverless app w/ AWS Lambda is fairly easy, but some documentation out there is outdated or using the preview toolkit. Below are some steps that show how to do this today, in a few steps. I’m using Visual Studio 2017. I’m also going to assume you already have your AWS credentials on your machine, if not, that’s a different topic.
- Install the AWS Toolkit for Visual Studio 2017 for Visual Studio. This is required to give you the project templates.
- Open Visual Studio and start a new project, choose “AWS Lambda Project” and give your project a name (I picked “awsLambdaTest”)
- At the Blueprint choice, choose “empty” then click “finish”.
- Your project will now create after a few seconds and should look like this:
- You can edit your code (in Function.cs)
- If you don’t edit anything and publish
- Now give your function a name and choose “next”:
- Now choose a role, the lambda_exec role is fine, then click “upload”.
- By default, the Lambda Function view will appear – this allows you to test your function. If you enter a string in the box under “sample input” and press “invoke”, you’ll see your function response.
Are .zip files ever going away? I remember back in the 90’s using WinZip as an alternative to the PKZip command line option. Anyway, fast forward 20+ years, and ZIP is still common and a great way to package files. Long story short: AWS Elastic Beanstalk allows you to easily deploy apps using a .zip file (if you haven’t tried Elastic Beanstalk – it’s pretty awesome) and I wanted a faster way to create a .zip of an app. (Yes, I know it’s not the best way to deploy like Git or the API).
There is a bunch of great sample code out there for creating ZIP archives in c# .Net using the ZipArchive Class in System.IO.Compression, but nothing seems to be a complete sample, showing multiple files. Below is what I’ve been using. One difference in this is changing the path separators from backslashes to forward-slashes. Without this, AWS wasn’t able to extract my .zip archive. I would see errors such as: Continue reading “Creating Valid ZIP Archives of Multiple Files in C# / .Net”
If you haven’t checked out Amazon’s new Polly (Text-to-Speech (TTS) cloud service) it does produce some pretty great, life-like audio. Below is a quick sample on how you can feed some text to Polly, and get an MP3 file with it. I don’t cover all of the install options of the AWS Toolkit for Visual Studio / .Net, but it’s pretty simple. (listen to this text here)
Below is some code:
AmazonPollyClient pc = new AmazonPollyClient();
SynthesizeSpeechRequest sreq = new SynthesizeSpeechRequest();
sreq.Text = "Your Sample Text Here";
sreq.OutputFormat = OutputFormat.Mp3;
sreq.VoiceId = VoiceId.Amy;
SynthesizeSpeechResponse sres = pc.SynthesizeSpeech(sreq);
using (var fileStream = File.Create(@"c:\yourfile.mp3"))
Also make sure you have the below included:
And these 2 NuGet packages added to your project:
This only scratches the surface of what Polly can do. Between streaming, SSML, Lexicons and more at a great price, I think we’ll be seeing more applications use this.