[Music]
hi my name is trevor sullivan i'm an AWS
solutions architect welcome to this
video in the dotnet learning series are
you using the python based AWS CLI to
deploy and manage your AWS cloud
resources today have you ever wished
that you could perform these same
automation tasks from an object-oriented
shell instead of a text-based shell like
bash or zsh since 2006 systems
administrators engineers and developers
have enjoyed the rich object-oriented
shell experience with PowerShell on the
Microsoft Windows platform AWS customers
have also enjoyed the benefits of an
object-oriented shell since the
availability of the AWS tools for
PowerShell also simply known as the AWS
PowerShell module however this powerful
shell isn't just limited to Windows
users any longer in January of 2018
Microsoft released the first generally
available version of PowerShell Core
Edition PowerShell core Edition is an
open source and cross-platform edition
of PowerShell that runs on top of the
cross-platform dotnet core framework
since the alpha version of PowerShell
core was first announced back in August
of 2016 the AWS PowerShell module has
had nearly full support for it through
the use of objects PowerShell reduces
the amount of work that's required to
construct complex inputs and parse
command output instead you can spend
more time focusing on your business
logic unlike the traditional bash or zsh
shell environment PowerShell offers
built-in utilities to sort filter and
even group objects together if required
you can even convert objects to and from
different common serialization formats
such as JSON and CSV without any third
party dependencies
even though objects are PowerShell
first-class citizens so to speak you
still have the ability to perform text
parsing through regular expressions now
that we've reviewed some of the
essential features of PowerShell let's
discuss how you can get started with
PowerShell and AWS automation today now
we're going to switch over to our web
browser and take a look at the
powershell project on github
using your web browser of choice head
over to the official powershell core
open source repository on github visit
the releases tab and download the latest
version of the powershell core package
for your operating system you can see
that powershell core supports a variety
of different operating systems including
Linux OS X and Windows after you've
installed PowerShell core you can launch
the shell using the executable named PW
SH instead of powershell exe as on the
Windows platform once you've launched
powershell installing the AWS PowerShell
module is easy
PowerShell has a public-facing NuGet
based module gallery known as the
powershell gallery similar to other
languages for example c-sharp developers
typically use nougat for hosting dotnet
packages where as JavaScript developers
might use the node package manager or
NPM to interact with the powershell
gallery powershell includes a small
module called powershell get this module
exports an array of commands that allows
you to install modules uninstall modules
and publish new modules to install the
AWS PowerShell module simply run this
install module command so we'll type the
install module command specify the name
parameter type the module name which is
AWS powershell dotnet core specify the
scope parameter of current user and that
instructs powershell to install the
module to our current users home
directory instead of the all users
directory that requires sudo permissions
and we'll just hit enter the module
should only take a few moments to
install from the powershell gallery once
it's installed you don't have to
manually import the module using the
import module command thanks to
powershell power shells module
autoloading feature with the AWS
PowerShell module installed it's time to
set up your credentials so that you can
access your AWS accounts resources if
you've already setup your AWS
credentials file manually or have been
using it with the AWS CLI you can most
likely skip this step if you haven't
already created an AWS credentials file
you can set it up using the following
PowerShell command the command name is
set AWS credential and then we'll
specify
a store as which is basically a profile
name that we'll use to reference this
access key ID then we'll specify our
access key and finally our secret key
you can generate these credentials from
the Identity and Access Management
Service inside the AWS management
console like the other SDKs the AWS
PowerShell module will automatically
look for the credentials profile named
defaults in your home directory under
the dot AWS hidden folder with
PowerShell installed along with the AWS
PowerShell module and your credentials
file configured you're now stood ready
to start exploring the PowerShell module
and performing automation tasks against
your AWS cloud resources the AWS
PowerShell module contains a helpful
command called get AWS command let name
this command will search for PowerShell
commands that invoke a specific AWS API
or interact with the AWS service more
generally for example we'll call get AWS
command let name - service lambda and
this will return a list of all the
lambda related PowerShell commands also
we'll call get AWS command let name
match with reg X bucket and this is
going to return any command that matches
the name bucket and then finally if we
want to get a specific PowerShell
command for a specific AWS API such as
put object we can use the API operation
parameter on the get AWS command let
name command if you've already deployed
some AWS lambda functions try calling
this command to obtain a list of them
from your AWS account so we'll type get
LM function list and as you can see I
get back a list of AWS lambda functions
from my AWS account you can also use the
native group object command in
PowerShell to group objects together
based on a common property this makes it
easy to run simple reports against your
AWS resources and get a count back in
the AWS lambda example try grouping them
together based on the configured memory
size or runtime so in this example we're
going to call get LM function list and
pipe that into the group
object command and then specify that we
want to group the objects together based
on the runtime property as you can see I
have lambda functions from Python 3.6
Python 2.7 as well as nodejs
you can also filter an array of objects
down to the objects that you care about
power shells where object command
provides a generic interface to filter
your objects based on certain criteria
for example let's say that we wanted to
find a list of aw s lambda functions
that matches a particular runtime so
we'll call the get LM function list
command again to retrieve a list of our
lambda functions and then we'll pipe it
into this where object command and
specify a filter script containing the
criteria returning either a true or
false value that matches the criteria we
want to filter on as you can see we've
filtered our list of lambda functions
down to only the ones that match the
Python 3.6 runtime if you need to
perform an action against many resources
at once you can use the powershell
pipeline for example let's say that you
wanted to delete all of your AWS lambda
functions that used the old Python 2.7
runtime the following command would
achieve that so we'll call the get LM
function list again with where object
and we're going to change our runtime to
Python 2.7 finally we're going to pipe
those objects into the remove LM
function command and if we hit enter
you'll see that all of those lambda
functions that match our criteria are
going to get to deleted if a command
doesn't exist to perform the operation
you're expecting you can instead pipe
your array of objects into the built in
for each object command in PowerShell
for example you could create a log entry
for an array of objects using this
command so we'll get a list of our
lambda functions once again and then
we'll pipe it into the for each object
command and specify a useful log entry
like the function named X has a y memory
size
and then we'll substitute our function
name and our memory size so that's going
to iterate over each lambda function and
generate a log entry for it before we
wrap up let's look at the JSON
conversion commands in PowerShell you
can use this command to find related
JSON commands in the shell environment
so we'll call it get command with a name
of star JSON star just as wildcards and
as you can see we've got the convert to
and convert from JSON commands that are
built directly into PowerShell if you're
starting to worry that these commands
look too long remember that you get
intellisense also known as tab
completion for both command and
parameter names out of the box make sure
that you use this feature to your
advantage
there are also built-in aliases for many
commands that can aid while typing out
commands interactively for example the
where object command has a default alias
of question mark the for each object
command has a default alias of % one of
the key advantages to powershell is that
the language reads naturally like plain
english although it may be different
from what you're used to with other
languages i think you'll find that this
is useful longer term especially in
shared code repositories this video was
a brief introduction to powershell
that barely even scratches the surface
of its depth as you can see PowerShell
is a powerful shell for both interactive
use as well as creating complex
applications I encourage you to install
PowerShell and spend some time learning
about its unique approach to interactive
command-line usage with its powerful
easy to understand commands data
processing features and cloud
integration with AWS I'm confident that
it will help you be more productive in
your work regardless of what role you
hold in your organization thanks for
watching this video in the dotnet
learning series and look for future
videos on AWS and PowerShell development
[Music]