profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Saturday, March 31, 2018

Setting up powershell with AWS

So I needed to setup my new powershell 6 with AWS. Didn't want to enter the credentials and all.
Install-Module -Name AWSPowerShell
Run this on your powershell 5 and/or 6 and you will have your aws tools for powershell ready to go.
Also run
notepad $profile
on powershell 5, powershell ISE, powershell 6 and copy paste the following, save them.
Import-Module AWSPowerShell
Also, if you want to be able to run scripts on your system then enable it toot by doing
Set-ExecutionPolicy RemoteSigned
Close all of your powershell windows now, launch powershell and run the following
Get-AWSPowerShellVersion -ListServiceVersionInfo
and you should get

PS C:\WINDOWS\system32> Get-AWSPowerShellVersion -ListServiceVersionInfo

AWS Tools for Windows PowerShell
Copyright 2012-2017, Inc. or its affiliates. All Rights Reserved.

Amazon Web Services SDK for .NET
Core Runtime Version
Copyright 2009-2015, Inc. or its affiliates. All Rights Reserved.

Release notes:

This software includes third party software subject to the following copyrights:
- Logging from log4net, Apache License

Service                               Noun Prefix API Version
-------                               ----------- -----------
AWS AppStream                         APS         2016-12-01 
AWS AppSync                           ASYN        2017-07-25 
AWS Batch                             BAT         2016-08-10 
AWS Budgets                           BGT         2016-10-20 
AWS Certificate Manager               ACM         2015-12-08 
AWS Cloud Directory                   CDIR        2016-05-10 
AWS Cloud HSM                         HSM         2014-05-30 
AWS Cloud HSM V2                      HSM2        2017-04-28 
AWS Cloud9                            C9          2017-09-23 
AWS CloudFormation                    CFN         2010-05-15 
AWS CloudTrail                        CT          2013-11-01 
AWS CodeBuild                         CB          2016-10-06 
AWS CodeCommit                        CC          2015-04-13 
AWS CodeDeploy                        CD          2014-10-06 
AWS CodePipeline                      CP          2015-07-09 
AWS CodeStar                          CST         2017-04-19 
AWS Config                            CFG         2014-11-12 
AWS Cost Explorer                     CE          2017-10-25 
AWS Cost and Usage Report             CUR         2017-01-06 
AWS Data Pipeline                     DP          2012-10-29 
AWS Database Migration Service        DMS         2016-01-01 
AWS Device Farm                       DF          2015-06-23 
AWS Direct Connect                    DC          2012-10-25 
AWS Directory Service                 DS          2015-04-16 
AWS Elastic Beanstalk                 EB          2010-12-01 
AWS Elemental MediaConvert            EMC         2017-08-29 
AWS Elemental MediaLive               EML         2017-10-14 
AWS Elemental MediaPackage            EMP         2017-10-12 
AWS Elemental MediaStore              EMS         2017-09-01 
AWS Elemental MediaStore Data Plane   EMSD        2017-09-01 
AWS Greengrass                        GG          2017-06-07 
AWS Health                            HLTH        2016-08-04 
AWS Identity and Access Management    IAM         2010-05-08 
AWS Import/Export                     IE          2010-06-01 
AWS Import/Export Snowball            SNOW        2016-06-30 
AWS IoT                               IOT         2015-05-28 
AWS IoT Jobs Data Plane               IOTJ        2017-09-29 
AWS Key Management Service            KMS         2014-11-01 
AWS Lambda                            LM          2015-03-31 
AWS Marketplace Commerce Analytics    MCA         2015-07-01 
AWS Marketplace Entitlement Service   MES         2017-01-11 
AWS Marketplace Metering              MM          2016-01-14 
AWS Migration Hub                     MH          2017-05-31 
AWS OpsWorks                          OPS         2013-02-18 
AWS OpsWorksCM                        OWCM        2016-11-01 
AWS Organizations                     ORG         2016-11-28 
AWS Price List Service                PLS         2017-10-15 
AWS Resource Groups                   RG          2017-11-27 
AWS Resource Groups Tagging API       RGT         2017-01-26 
AWS Security Token Service            STS         2011-06-15 
AWS Serverless Application Repository SAR         2017-09-08 
AWS Service Catalog                   SC          2015-12-10 
AWS Shield                            SHLD        2016-06-02 
AWS Storage Gateway                   SG          2013-06-30 
AWS Support API                       ASA         2013-04-15 
AWS WAF                               WAF         2015-08-24 
AWS WAF Regional                      WAFR        2016-11-28 
AWS X-Ray                             XR          2016-04-12 
Alexa For Business                    ALXB        2017-11-09 
Amazon API Gateway                    AG          2015-07-09 
Amazon Athena                         ATH         2017-05-18 
Amazon CloudFront                     CF          2017-03-25 
Amazon CloudSearch                    CS          2013-01-01 
Amazon CloudSearchDomain              CSD         2013-01-01 
Amazon CloudWatch                     CW          2010-08-01 
Amazon CloudWatch Events              CWE         2015-10-07 
Amazon CloudWatch Logs                CWL         2014-03-28 
Amazon Cognito Identity               CGI         2014-06-30 
Amazon Cognito Identity Provider      CGIP        2016-04-18 
Amazon Comprehend                     COMP        2017-11-27 
Amazon DynamoDB                       DDB         2012-08-10 
Amazon DynamoDB Accelerator (DAX)     DAX         2017-04-19 
Amazon EC2 Container Registry         ECR         2015-09-21 
Amazon EC2 Container Service          ECS         2014-11-13 
Amazon ElastiCache                    EC          2015-02-02 
Amazon Elastic Compute Cloud          EC2         2016-11-15 
Amazon Elastic File System            EFS         2015-02-01 
Amazon Elastic MapReduce              EMR         2009-03-31 
Amazon Elastic Transcoder             ETS         2012-09-25 
Amazon Elasticsearch                  ES          2015-01-01 
Amazon GameLift Service               GML         2015-10-01 
Amazon GuardDuty                      GD          2017-11-28 
Amazon Inspector                      INS         2016-02-16 
Amazon Kinesis                        KIN         2013-12-02 
Amazon Kinesis Analytics              KINA        2015-08-14 
Amazon Kinesis Firehose               KINF        2015-08-04 
Amazon Kinesis Video Streams          KV          2017-09-30 
Amazon Kinesis Video Streams Media    KVM         2017-09-30 
Amazon Lex                            LEX         2016-11-28 
Amazon Lex Model Building Service     LMB         2017-04-19 
Amazon Lightsail                      LS          2016-11-28 
Amazon MQ                             MQ          2017-11-27 
Amazon MTurk Service                  MTR         2017-01-17 
Amazon Machine Learning               ML          2014-12-12 
Amazon Pinpoint                       PIN         2016-12-01 
Amazon Polly                          POL         2016-06-10 
Amazon Redshift                       RS          2012-12-01 
Amazon Rekognition                    REK         2016-06-27 
Amazon Relational Database Service    RDS         2014-10-31 
Amazon Route 53                       R53         2013-04-01 
Amazon Route 53 Domains               R53D        2014-05-15 
Amazon SageMaker Runtime              SMR         2017-05-13 
Amazon SageMaker Service              SM          2017-07-24 
Amazon Server Migration Service       SMS         2016-10-24 
Amazon Simple Email Service           SES         2010-12-01 
Amazon Simple Notification Service    SNS         2010-03-31 
Amazon Simple Queue Service           SQS         2012-11-05 
Amazon Simple Storage Service         S3          2006-03-01 
Amazon Simple Systems Management      SSM         2014-11-06 
Amazon Step Functions                 SFN         2016-11-23 
Amazon Translate                      TRN         2017-07-01 
Amazon WorkDocs                       WD          2016-05-01 
Amazon WorkSpaces                     WKS         2015-04-08 
Application Auto Scaling              AAS         2016-02-06 
Application Discovery Service         ADS         2015-11-01 
Auto Scaling                          AS          2011-01-01 
Elastic Load Balancing                ELB         2012-06-01 
Elastic Load Balancing V2             ELB2        2015-12-01 

PS C:\WINDOWS\system32> 

So this means we have the AWS module working. but we want to be able to get this working but we want to set it in a way where it won't ask for credentials so that we can use provisioning tools like vagrant, ansible or chef.
Now we have to create a profile and set aws access to that so that we can perform activities without credentials.

$accessKey = 'ADFASGALKJCUIERHL' # fake example
$secretKey = 'SADFDSGDFH5d6+1P2pmIGW8fdkekdfsneujK14u' # fake example
$profileName = 'myProfileName' # fake example
Set-AWSCredential -AccessKey $accessKey -SecretKey $secretKey -StoreAs $profileName

So now the profile has our credentials stored. Let us now set a default region as Asia Pacific (Singapore)

Initialize-AWSDefaultConfiguration -ProfileName $profileName -Region ap-southeast-1
So we are all done. We can provision stuff from from AWS powershell with ease.

PS C:\WINDOWS\system32> Get-AWSRegion

Region         Name                      IsShellDefault
------         ----                      --------------
ap-northeast-1 Asia Pacific (Tokyo)      False         
ap-northeast-2 Asia Pacific (Seoul)      False         
ap-south-1     Asia Pacific (Mumbai)     False         
ap-southeast-1 Asia Pacific (Singapore)  True          
ap-southeast-2 Asia Pacific (Sydney)     False         
ca-central-1   Canada (Central)          False         
eu-central-1   EU Central (Frankfurt)    False         
eu-west-1      EU West (Ireland)         False         
eu-west-2      EU West (London)          False         
sa-east-1      South America (Sao Paulo) False         
us-east-1      US East (Virginia)        False         
us-east-2      US East (Ohio)            False         
us-west-1      US West (N. California)   False         
us-west-2      US West (Oregon)          False    
As you can see currently I have sen my default region as singapore.
Note: Powershell 6 somehow isn't playing well yet. May be in future it will. Everything howerver worked great with powershell 5.

No comments:

Post a Comment