-->

Usually, the login URL for IAM users is in this format

https://{Account Id}.signin.aws.amazon.com/console

But it is possible to make this URL more memorable and user-friendly.

To achieve this, follow the steps below:

Step 01: Go to IAM Dashboard

Step 02: Click on the Create link that is located right next to the account id:

AWS IAM dashboard showing Account Alias section with a Create button

Step 03: This brings up the Create Account Alias dialog box.

Create alias for account dialog is shown

Step 03: Enter your desired alias and save.

Create alias for account dialog with preferred alias value provided. It shows an information box saying IAM users can still access the account by account id

Since the name we provide goes in the URL, it must be unique globally.

If you don’t pick a unique name, you will get an error like this:

Error message box saying alias not created because it already exists

and when you choose your unique name, you should see it in effect:

IAM dashboard showing account alias created

You can keep on using the account id. Setting an alias gives an additional URL that you can use.

Resources

aws s3

Yesterday I had to find the count of objects in a folder in an S3 bucket. Unfortunately, I only had access to AWS via the command line and was working on a Windows Server.

Using AWS CLI

After digging around, I found the solution using PowerShells’ Measure-Object cmdlet.

The solution to getting the object count was:

aws s3 ls s3://{bucket}/path/to/files | Measure-Object

You can use it in local folders as well. It also can be used to get the minimum/maximum/average/total size of the folder too so quite handy to get some quick stats about a folder/bucket

Using AWS Tools for PowerShell

If you have AWS Tools for PowerShell installed, you can achieve the same goal by running the Get-S3Object cmdlet like this:

Get-S3Object -BucketName {bucket} -Prefix path/to/files | Measure-Object

Alternatively, if you want to get the object count, you can run this as well:

(Get-S3Object -BucketName {bucket} -Prefix path/to/files).Count

Resources

dev powershell

Sometimes I’m amazed by how some tasks are easy to carry out using PowerShell. One such task is converting common data types such as CSV, JSON and XML. PowerShell has built-in support for all these types.

Convert CSV to JSON

For example, let’s say we have the following customer data in a CSV file named customers.csv

Id,FirstName,LastName,Country,Status
1,James,Monroe,USA,Active
2,Diane,Wheatley,UK,Active
3,Sara,Bailey,UK,Suspended

If we want to convert this data into JSON, we can run the following command in PowerShell:

Import-Csv ./customers.csv | ConvertTo-Json | Out-File ./customers.json

we get the following JSON output:

[
  {
    "Id": "1",
    "FirstName": "James",
    "LastName": "Monroe",
    "Country": "USA",
    "Status": "Active"
  },
  {
    "Id": "2",
    "FirstName": "Diane",
    "LastName": "Wheatley",
    "Country": "UK",
    "Status": "Active"
  },
  {
    "Id": "3",
    "FirstName": "Sara",
    "LastName": "Bailey",
    "Country": "UK",
    "Status": "Suspended"
  }
]

The output JSON is indented by default, so very easy to read as well.

Convert JSON to CSV

If we want to reverse the process and create a CSV file from a JSON input, we can run the following:

(Get-Content -Path ./customers.json -Raw | ConvertFrom-Json) | Export-CSV ./customers.csv

and get a CSV that looks like:

"Id","FirstName","LastName","Country","Status"
"1","James","Monroe","USA","Active"
"2","Diane","Wheatley","UK","Active"
"3","Sara","Bailey","UK","Suspended"

I used the Export-CSV cmdlet in this example because it saves the output to a file. We can also use ConvertTo-Csv cmdlet

For example, the following snippet print the results to the console:

(Get-Content -Path ./customers.json -Raw | ConvertFrom-Json) | ConvertTo-Csv | Write-Host

Convert JSON to XML

Similar to JSON, we can use the ConvertTo-XML cmdlet to create an XML file out of our sample JSON:

Export-Clixml -Depth 3 -InputObject ((Get-Content -Path ./customers.json -Raw) | ConvertFrom-Json) -Path ./customers.xml

and the output looks like this:

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>System.Object[]</T>
      <T>System.Array</T>
      <T>System.Object</T>
    </TN>
    <LST>
      <Obj RefId="1">
        <TN RefId="1">
          <T>System.Management.Automation.PSCustomObject</T>
          <T>System.Object</T>
        </TN>
        <MS>
          <S N="Id">1</S>
          <S N="FirstName">James</S>
          <S N="LastName">Monroe</S>
          <S N="Country">USA</S>
          <S N="Status">Active</S>
        </MS>
      </Obj>
      <Obj RefId="2">
        <TNRef RefId="1" />
        <MS>
          <S N="Id">2</S>
          <S N="FirstName">Diane</S>
          <S N="LastName">Wheatley</S>
          <S N="Country">UK</S>
          <S N="Status">Active</S>
        </MS>
      </Obj>
      <Obj RefId="3">
        <TNRef RefId="1" />
        <MS>
          <S N="Id">3</S>
          <S N="FirstName">Sara</S>
          <S N="LastName">Bailey</S>
          <S N="Country">UK</S>
          <S N="Status">Suspended</S>
        </MS>
      </Obj>
    </LST>
  </Obj>
</Objs>

A bit noisy, but the data is there.

Conclusion

Using PowerShell’s built-in cmdlets, we can easily convert between common data types such as CSV, JSON and XML. For a complete list of supported cmdlets, please check the link in the resources section.

Resources