After deploying a gazillion Episerver sites to Azure I thought it would be nice to play with Amazon AWS Elastic Beanstalk. Only because I wanted to see if it is just as easy to deploy a website to AWS as it is with Azure.
The documentation on Episerver World is quite extensive, however some pieces seem to be missing and there are some pitfalls, so I hope this blogpost will help you out with your deployments.
Here is what we are going to do:
- Create a free AWS account
- Create a user for this deployment
- Install AWS Toolkit in Visual Studio
- Setup the database instance
- Prepare the database
- Prepare the solution (Alloy)
- Deploy to AWS Elastic Beanstalk
1. Create a free AWS account
If you already have an AWS account you can skip this step.
Goto https://aws.amazon.com/ and select “Create free account”. After you have been validated you end up in the AWS console.
2. Create a user for this deployment
Amazon recommends not to use your root account for day-to-day interaction with AWS, because it has unrestricted access to all your resources. So let’s create a new user.
[column size=”three-fifth”]In the AWS console, select Identity and Access Management.
Select users in the menu and click “Create New User”
Enter the username(s) you want to use and click “Create”.[/column][column size=”two-fifth” last=”true”][/column]
Download or copy the User Security Credentials, you will need them later for creating a profile in the AWS Explorer and configuring the providers.
Select the created user and click “Manage Password” in the User Action drop-down menu.
Enter a password for the user.
Next create a group, for example “Episerver” and attach the appropriate policies to this group.
We will use the following resources: Elastic Beanstalk, EC2, RDS and SNS/SQS. Adding AWSElasticBeanstalkFullAccess will give us the correct rights.
Finally add the user(s) to the group and we are ready to go.
The username and password you just created will be used to login to the AWS console the next time.
The login url is displayed in the dashboard page and should look like: https://12345678.signin.aws.amazon.com/console
You can change the account number for some custom name if you want.
Logout the root account.
3. Install AWS Toolkit in Visual Studio
[column size=”three-fifth”]The AWS toolkit is an extension for Visual Studio that lets you manage your resources in AWS and makes it easy to deploy.
Go to http://aws.amazon.com/visualstudio/ to download the latest version of the AWS toolkit.
After installation you can create a new profile in the AWS Explorer by using the security credentials we saved earlier.[/column][column size=”two-fifth” last=”true”][/column]
4. Setup the database instance
You can either setup the database instance from the AWS Console or from Visual Studio.
Be sure to select the right region for your resources.
[column size=”three-fifth”]Using AWS Console:
Login with the security credentials you just created.
In the AWS console go to RDS[/column][column size=”two-fifth” last=”true”][/column]
[column size=”three-fifth”]Create a new database instance of type SQL Server Express.
As the DB Instance Class select db.t2.micro, because that one is free and will do fine for this demo.
You can leave the rest of the instance settings to the default.
At settings specify a name for your database instance and enter a master username and password.
In the next step at “Configure Advanced settings” you can use the default settings. Be sure “Publicly Accessible” is set to YES, else you won’t be able to connect to your DB instance from Visual Studio or SQL Server Management Studio.
Click “Launch DB instance” to start your database server.[/column][column size=”two-fifth” last=”true”][/column]
[column size=”three-fifth”]Using Visual Studio:
In the AWS explorer right click on Amazon RDS and select “Launch Instance”.
This will open up a wizard.
Select SQL Server Express.
Select the DB Engine version you need.
As the DB Instance Class select db.t2.micro, because that one is free and will do fine for this demo.
Specify a name for your database instance and enter a master username and password.[/column][column size=”two-fifth” last=”true”][/column]
[column size=”three-fifth”]In the next step be sure to check the “Publicly accessible” option, else you won’t be able to connect to your DB instance from Visual Studio or SQL Server Management Studio.
Also check “Create new security group”. This will create a new security group which includes your IP address, so you can access the DB instance.
You can leave the rest of the setting to their default values.[/column][column size=”two-fifth” last=”true”][/column]
5. Prepare the database
[column size=”three-fifth”]Now that we have our DB instance up and running, we can create the database.
In the AWS Explorer in Visual Studio right click the DB instance and select “Create SQL Server Database”.
When the database is created we we automatically be taken to the Server Explorer.[/column][column size=”two-fifth” last=”true”][/column]
6. Prepare the solution (Alloy)
In Visual Studio create a new Alloy project. Do not include search in the project.
Add the following package to the solution: EPiServer.Amazon.
In the web.config file we have to add 2 items to the episerver.framework section:
Blob provider
<blob defaultProvider="s3blobs"> <providers> <add name="s3blobs" type="EPiServer.Amazon.Blobs.AmazonBlobProvider,EPiServer.Amazon" accessKey="<your accesskey>" secretKey="<your secretkey>" region="<region code>" bucket="alloymedia" /> </providers> </blob>
You will need the accessKey and secretKey from the user we created in step 2.
Information about the region code can be found here: http://docs.aws.amazon.com/general/latest/gr/rande.html#rds_region
For the bucket you can take any name you want. The bucket will be created automatically after deployment if it doesn’t exist.
Event provider
<event defaultProvider="amazonevents"> <providers> <add name="amazonevents" type="EPiServer.Amazon.Events.AmazonEventProvider,EPiServer.Amazon" accessKey="<your accesskey>" secretKey="<your secretkey>" region="<region code>" topic="alloyevents" /> </providers> </event>
You will need the accessKey and secretKey again from the user we created in step 2.
Information about the region code can be found here: http://docs.aws.amazon.com/general/latest/gr/rande.html#sns_region
For the topic you can take any name you want. The topic will be created automatically after deployment if it doesn’t exist.
We also have to configure the correct connection string. It should look like this:
<add name="EPiServerDB" connectionString="Server=tcp:episerver.cgx4wqop9hds.eu-west-1.rds.amazonaws.com,1433;Database=dbAlloy;User ID=sa;Password=<your password>;Connection Timeout=30;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
[column size=”three-fifth”]You can find the name of the server by right clicking on the instance and copy the address, or by looking at the properties.
Note: normally I would not recommend to use the sa user for connecting to the database. You can easily create a new user by using SQL Server Management Studio.
For now we will use the sa account.[/column][column size=”two-fifth” last=”true”][/column]
As a final step before deployment we need to install the database schema.
Open the SQL script from: packages\EPServer.CMS.Core.x.y.z\tools\EPiServer.Cms.Core.sql and execute it against the database.
Now we are finally ready for the real deployment.
7. Deploy to AWS Elastic Beanstalk
[column size=”three-fifth”]Right-click on the project and select “Publish to AWS”, the publication wizard will open.
Select the right profile and region and select “Create a new application environment”.[/column][column size=”two-fifth” last=”true”][/column]
[column size=”three-fifth”]Enter a name for the application, environment and url, or choose one of the defaults.[/column][column size=”two-fifth” last=”true”][/column]
[column size=”three-fifth”]You can leave most of the AWS settings to their default. Be sure instance type is set to t2.micro, because that’s the free one.
At Relational Database Access select the security group for your VPC[/column][column size=”two-fifth” last=”true”][/column]
[column size=”three-fifth”]Leave Application Options also default for now.[/column][column size=”two-fifth” last=”true”][/column]
[column size=”three-fifth”]Review all the settings. When everything is ok, press Deploy[/column][column size=”two-fifth” last=”true”][/column]
After the deployment you might run into a few issues.
Access to the path ‘C:\inetpub\wwwroot\modules\_Protected\repository.config’ is denied
By default the application pool user is not allowed to write to the disk. A workaround for this issue is to run the site locally once and include the generated repository.config file in the project. Then redeploy the site.
Another option is to create a folder in the root of your project named “.ebextensions”.
In that folder create a config file, for example AlloyEB.config and add the following lines to it:
commands: 01-set-permissions: command: icacls C:\\inetpub\\wwwroot\\modules\\_Protected /grant:r "IIS_IUSRS":(OI)(CI)M