Hello AWS solution architect Trevor Sullivan Welcome to the.

NET Learning Series Videos Did you know that you can create custom events yourself in the AWS cloud? There are several ways to create a custom event For example, you can send a message to a Simple Notification Service (SNS) topic In addition, to Amazon CloudWatch event service Another way is to send event data By default for many of the other AWS services Primary notifications are sent to CloudWatch events But what if you want to create a custom event notification yourself You can also create such notifications As an example, for important files in the EC2 instance Consider the case of creating a local backup Once the backup is complete, use a local script Upload backup archive to Amazon S3 bucket Second, use the Lambda function, which has short execution time and cost-effectiveness, to save on storage costs.

Delete the oldest backup However, the backup and upload process has been completed on the EC2 instance.

How can you find it with the Lambda function? Here is where the CloudWatch event comes into play You can use CloudWatch Events to find other AWS cloud services You can trigger the target Such targets include AWS Step Functions, SNS Topics Contains the commands to run Systems Manager It also targets AWS Lambda functions For the rest of this video, use AWS Tools for PowerShell Your own custom application event Let's look at how to send to the Amazon Cloud Watch service AWS Tools for PowerShell (also called an AWS PowerShell module) After installing Set up the credentials file.

Then you are ready A separate video explains how to set up your credentials If you're new to AWS or are not familiar with PowerShell Please check it and see the rest of this video First of all To manipulate the API for CloudWatch Events Let's look at AWS PowerShell commands Use the Get-AWSCmdletName command to manipulate the API for Cloud Watch events Get a list of commands that correspond to the AWS service name Let's switch to the shell and enter the Get-AWSCmdletName command Designate as -Service events You do not need to know the service name exactly Also, you don't have to enter the full service name Enter part of a unique service name, such as event Pattern matching is performed Then, in response, it performs various actions on CloudWatch Event Service A list of dozens of PowerShell commands is displayed Notice the Write-CWEEvent command here This command is then used to write custom events to CloudWatch Now we know the PowerShell command to call So how do you know the parameters to specify for that command? Here is the help system built into PowerShell To know how to invoke the command correctly Call Get-Help command to get command signature Well, back to the shell Invoke the Get-Help -name Write-CWEEvent command As you can see from the embedded document The only parameter that can be specified with this command is -Entry However, if you look at the data types that can be entered in the -Entry parameter That's in the Amazon.



NET namespace You can see that it is a.

NET object type In order to call this command correctly First create an instance of the PutEventsRequestEntry.

NET class Set some properties of that instance You need to specify this instance when calling the command There are two ways to instantiate.

NET objects in PowerShell First, specify the typeName parameter You can use the traditional New-Object command Also, in PowerShell 5.

0, there is a static new method for calling a class constructor It has been introduced and there is also a way to use it Let's look at this method Switch to shell After specifying the Amazon.



PutEventsRequestEntry class Reference the new method of that class Referencing a constructor or method without parentheses A list of overloads for that method is printed This time, only one default constructor is displayed in the parameter list Let's use this Now, actually call this constructor Assign a new object instance to a variable called myevent Return to the shell and create a variable called myevent Set this variable as a new instance of the PutEventsRequestEntry class Yes You have now created a new object.

Well, let's move on Before specifying this object with the Write-CWEEvent command You need to set some properties on this object How do I know which property to set First of all Specify this object with the Get-Member command of PowerShell Can perform type reflection of the object Then you will see the properties and methods of that object Also, as a legitimate source, with Amazon CloudWatch documents Examine the PutEvents API You also need to know what you can enter for this service Let's look at the Get-Member command First we need to set the Time property of this event This property represents the date and time when the event occurred To set this property, reference the myevent variable that contains the event object Specify the Time property Set as output of Get-Date This will output the current date and time as it is Then, if necessary, the relevant AWS cloud resources You can also add it to a string collection Although setting of Resources property is not mandatory If you set this property, you can access specific resources in your AWS account.

Useful for correlating application events When adding a string to this property The string must be enabled in Amazon Resource Names (ARN) You can also set this Detail property to a valid JSON string Because this property outputs the context of the event You can notify the event receiver what is happening Let's do it.

Switch to shell Get the Detail property Set the contents in the PowerShell hash table and then Separated by pipe, specified by built-in ConvertTo-Json command Enter $ myevent.

Detail You can see that a valid JSON string is set Also indicates the trigger source of the event You also need to set the Source property In the Source property You can just set a string like "PowerShell", though Uniquely represent a PowerShell instance It is convenient to set the PowerShell execution space instance ID It uses a log file that contains the PowerShell execution space instance ID Especially useful when debugging a program Let's set the Source property Input $ myevent.

Source = $ host.



Guid Let's try If you look at the Source property I know the execution space ID Finally, you need to set the DetailType property This is a custom field that specifies the type of event that occurred So, $ myevent.

DetailType = 'Something.

Happened' Enter After setting all myevent objects You will be able to call the Write-CWEEvent command You can just call the Write-CWEEvent command.

In that case, specify the -Entry parameter specify myevent variable To use events sent from a custom PowerShell application Need to set CloudWatch event rules I will explain this in another video Let's do it.

Execute Write-CWEEvent Specify -Entry, then specify myevent The already configured entry is output You can see that the command was successfully executed So far, from PowerShell to Amazon CloudWatch I explained how to send a custom event Involved in PowerShell development on AWS There will be more videos available, so please take a look Thank you very much.