Create your own metrics in AWS Cloudwatch

To use CloudWatch Create your own metrics, by e.g.. alarm and to operate monitoring with the data of the application, can you use the aws-php-sdk use the following code:

 $client = new CloudWatchClient([
        'region' => 'eu-central-1',
        'version' => '2010-08-01',
        'credentials' => [
            'key'    => 'xxx',
            'secret' => 'xxx
$result = $this->client->putMetricData(array(

    'Namespace' => 'MyProject',
    'MetricData' => array(
            'MetricName' => 'MyMetric,
            'Timestamp' => time(),
            'Value' => 1,
            'Unit' => 'Count',
            'Dimensions' => array(
                    'Name' => 'Environment',
                    'Value' => 'test',

Use Docker Shell Alias on Linux

In order to use the Linux Shell to use the usual aliases such as Ll for ls -lh to use, you have to use the following trick:

Since the login via sh is not a Linux login shell, the alias definitions are /etc/profile.d not loaded at login.


Enough, deal with Sh –login in the container, then the alias definitions are available.

DockerFile PHP with XDebug and Amazon Linux 2

A DockerFile for a PHP 7.2. Environment with XDebug for a Symfony 4 Environment on Amazon Linux 2:

FROM amazonlinux:2.0.20190823.1

RUN yum install -y

# install php
RUN amazon-linux-extras install -y php7.2
RUN yum install -y php-devel.x86_64 php-xml.x86_64 php-pecl-zip.x86_64  php-intl.x86_64

#install xdebug
RUN yum install -y gcc make
RUN yum install -y php-pear.noarch
RUN pecl install xdebug
RUN echo 'zend_extension=/usr/lib64/php/modules/' >> /etc/php.ini

Docker Xdebug remote_host setzen in Toolbox für PHPStorm

To debug with Xdebug and PHPStorm in the Docker Container, but gets the error message:

Connection was not established. Probably '' is incorrect

this is due to the, that Docker in the Toolbox variant for Windows has the placeholder not filled. So the IP of the PHPStorm computer has to be set manually.

To do this, you manually set the value of xdebug.remote_host to (the IP Docker sets for the host, can varnise) cli interpreter options:


Docker Directory Mount on Windows 10 with Docker Toolbox

To place a local folder in a Docker Container on Windows 10 to mount, you can either use Docker for Windows or if you are using the Windows 10 Home Edition used, one is forced, This by hand with Virtual Box Do.

To do this, you have to use the Docker default Select Box in Virtual Box:


and add a new Shared Folder:virtual_box_shared_folder_add

Then you have to restart the docker-machine in the Docker Toolbox, this will restart the docker default Virtual Box:

docker-machine restart

Now you can mount your directory in his docker-compose.yml:

  - /htdocs/my_project:/var/www/html/

Now the folder in the Docker container is successfully mounted.

The following command can be used to test, whether the mount was successful:

docker exec -it CONTAINER_ID ls -ll /var/www/html

Configuring Monolog Logging for AWS Cloudwatch Logs

So that the logs are beautifully formatted from a Symfony 4 Arrive application in AWS Cloudwatch, must be Monologue configure as follows:

# config/services.yaml
        - [includeStacktraces]


# config/packages/prod/monolog.yaml
      type:  stream
      level: error
      path:  '%kernel.logs_dir%/error.log'
      formatter: Monolog\Formatter\JsonFormatter

After that, you have to Cloudwatch Daemon to configure:

# /etc/awslogs/awslogs.conf
# Path to the CloudWatch Logs agent's state file. The agent uses this file to maintain
# client side state across its executions.
state_file = /var/lib/awslogs/agent-state

datetime_format = [%Y-%m-%d H:%M:%S]
file = /var/www/html/var/log/error.log
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = test_group_name/error_log

and you get wonderful (Aggregated) ErrorLog Information in Cloudwatch Logs Insight:



11 AWS Cloudformation Expert Tricks

I've collected a lot of useful tips in my work with Cloudfromation, which I would like to share.

1. Using an IDE with Autocomplete

For the Jetbrains IDEs like PHPStorm, Webstorm or IntelliJ there is a very good AWS Cloudfromation plugin called AWS Cloudfromation by Leonid Shalupov:

AWS Cloudfromation Plugin by Leonid Shalupov

This offers Autocomplete for the IDE and an automatic format check, whether attributes are set, which are not allowed there. On this way you can find many errors even before validating and saves a lot of time.

AWS Cloudfromation Autocomple

2. Using AWS CLI Commands more…

Cloud formation reboot of an EC2 instance

To restart an instance, after the setup has been done, the following command must be entered in the UserData section in the Cloudformation Template:

  # is executed as root user
    !Sub |
      #!/bin/bash -xe
      yum update -y aws-cfn-bootstrap
      /opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource WebServerInstance --configsets InstallAndRun --region ${AWS::Region}
      /opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource WebServerInstance --region ${AWS::Region}