Giter Site home page Giter Site logo

danmgs / aws.beanstalk.webapplication Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 1.08 MB

A demo web application in .NET Core for AWS Elastic Beanstalk with X-Ray

C# 53.45% HTML 41.05% Batchfile 1.14% CSS 3.62% JavaScript 0.74%
aws beanstalk netcore csharp dynamodb windows configuration amazon-web-services x-ray xray

aws.beanstalk.webapplication's Introduction

AWS.Beanstalk.WebApplication

A demo web application in .NET Core for AWS Elastic Beanstalk.

It is leveraging AWS DynamoDB and X-Ray services, via configuration files.

1. Folder organization

Main components are highlighted below :

|
| -- /AWS.Beanstalk.WebApplication/                               -> the .NET application
        |
        | -- appsettings.json                                     -> The configuration file
        |
        | -- /Controllers/
                | -- ProductController.cs
        |
        | -- /scripts/
                | -- /deploy/
                        | -- aws-windows-deployment-manifest.json -> manisfest for deployment under Windows IIS
                | -- build.bat                                    -> script for build the .NET application
                | -- deploy.bat                                   -> script for deployment to elasticbeanstalk

When running for development locally, you should configure appsettings.json with correct region and create a dynamodb named "Product" table manually.

2. Prerequisites

2.1 Create an EC2 Profile

Your elasticbeanstalk environment will launch EC2 instance(s) with the default AWS role :

  • "aws-elasticbeanstalk-ec2-role". You need extend it with additionnal policies:

    • SSM Role (optional) to log into EC2 via AWS Session manager console for debug. So, there's no need to attach the EC2 any keypair and any security group with RDP ingress rule.
    • Custom inline policy "MyCustomPolicy" (mandatory) for DynamoDB, X-Ray, SNS operations defined as below:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "CustomPolicy",
            "Effect": "Allow",
            "Action": [
                "sns:Publish",
                "dynamodb:PutItem",
                "dynamodb:DescribeTable",
                "dynamodb:DeleteItem",
                "dynamodb:GetItem",
                "dynamodb:Scan",
                "dynamodb:UpdateItem",
                "xray:GetSamplingStatisticSummaries",
                "xray:PutTelemetryRecords",
                "xray:GetSamplingRules",
                "xray:GetSamplingTargets",
                "xray:PutTraceSegments"
            ],
            "Resource": "*"
        }
    ]
}

EC2 profile should look like:

alt capture

2.2 Setup the eb-cli and create an eb configuration

  • You must install the eb-cli in order to the script\build.bat to make the deployment to elasticbeanstalk.

You may require to install python first.

  • Go to script\deploy directory, type command:
eb init

Follow instructions to generate the elasticbeanstalk application and its environment in elasticbeanstalk console.

Click to expand details

alt capture

This will generate the configuration file AWS.Beanstalk.WebApplication\scripts\deploy\.elasticbeanstalk\ which will be used further by the script\deploy.bat.

To create the environment, you can use command:

# this command create an environment based on your parameters

eb create

BUT I prefer to create it via the elasticbeanstalk console with following options:

Configuration Value to select Comments
Environment type Web server environment
Application name Appdemo name it as you like
Environment name Appdemo-env name it as you like
Platform .NET (Windows/IIS)
Application code default sample application
IAM Instance Profile aws-elasticbeanstalk-ec2-role refer Prerequisites section
  • Once the environment created,

set the default environment, you have just created (I named it Appdemo-env) for further deployment.

eb use Appdemo-env

3. Getting started

  • Go to directory AWS.Beanstalk.WebApplication\scripts, in order :

    • run the script build.bat to build the application.

    This will generate into the temporary output directory.

    • run the script deploy.bat to deploy the application.

    This will generate a bundle zipfile into the deploy directory.

    The bundle will automatically be uploaded to your elasticbeanstalk environment, by leveraging the eb deploy command against your elasticbeanstalk configuration.

  • The bundle contains:

    • the application binaries

    • .ebextensions configuration files for:

      • custom environment variables (in elasticbeanstalk console: Configuration > Software > Environment properties)

      • aws resources such as Dynamodb "Product" table

      • X-Ray daemon setup

      • a manifest file "aws-windows-deployment-manifest.json" describing the deployment in IIS

      • elasticbeanstalk configuration

  • Once the environment is ready, browse the website:

    • play with the product page.

    Product items will be stored and retrieved from generated Product dynamoDB table.

    Service map in X-Ray:

    alt capture

    You can filter traces on annotations via the search bar, by example:

    # filter on create product operation
    annotation.operationType="CreateProduct"
    
    # filter on all type of operations with product
    annotation.operationType CONTAINS "Product"
    

๐Ÿ”Ž Filtering

Click to expand details

alt capture

alt capture

alt capture

4. Useful resources

5. Some useful commands when connected into EC2

  # View application custom logs
    cat C:\logs\xray-sdk.log
    cat C:\logs\webapp.log
    cat C:\logs\all.log
  # List all started services in windows
    net start
  # Stop and start any service: net stop/start servicename
    net stop "AWS X-Ray"
    net start "AWS X-Ray"
  # Restart IIS
    iisreset

aws.beanstalk.webapplication's People

Contributors

danmgs 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.