Using AWS Powershell to deploy to AWS elastic beanstalk - powershell

Hi I am trying to deploy onto Elastic Beanstalk using AWS Powershell.
Currently I am just trying to get the EB environment using the following cmdlet:
+ Get-EBEnvironment
-ApplicationName
-EnvironmentId
-VersionLabel
-EnvironmentName
-IncludedDeletedBackTo
-IncludeDeleted
This is the cmdlet I used: Get-EBEnvironment -ApplicationName appName
However, I am getting the following error:
Get-EBEnvironment : No region specified or obtained from persisted/shell defaults.
At C:\Users\lowong\Desktop\script.ps1:22 char:1
Get-EBEnvironment -ApplicationName evcfacade
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (Amazon.PowerShe...vironmentCmdlet:GetEBEnvironmentCmdlet) [Get-EBEnvironment], InvalidOperationException
FullyQualifiedErrorId : InvalidOperationException,Amazon.PowerShell.Cmdlets.EB.GetEBEnvironmentCmdlet
Am I missing other fields I have to put onto the cmdlet? or what's the problem?
(Here's the link to the documentation of the cmdlet: http://docs.aws.amazon.com/powershell/latest/reference/index.html?page=New-EBApplicationVersion.html&tocid=New-EBApplicationVersion)

The error mentions the following:
No region specified or obtained from persisted/shell defaults.
So, you have 2 possible resolutions:
Include the -Region parameter, such as -Region us-east-1. See Get-EBEnvironment Cmdlet. Or
Use the Set-DefaultAWSRegion cmdlet to set the default region. See Set-DefaultAWSRegion Cmdlet

Note that Set-DefaultAWSRegion is not persisted (you have to specify it for every powershell session).
If you want to persist region, it can be done as part of setting up your credentials with:
Initialize-AWSDefaults -ProfileName {profileName} -Region {region}
For more information see: Specifying Credentials

Related

Add-AzureRmServiceFabricNodeType -> 'accountName' cannot be null

I'm trying to use the 'Add-AzureRmServiceFabricNodeType' command to add a new nodeType to an existing service fabric cluster. This is my command:
Add-AzureRmServiceFabricNodeType -ResourceGroupName "$ResourceGroupName$" -Name "$ClusterName$" -NodeType "$TypeName$" -VmSku "Standard_H8" -Capacity 3 -VmUserName "$UserName$" -VmPassword $pwd
Having already logged in and set the subscription using 'Login-AzureRmAccount' and 'Set-AzureRmContext'
The call runs for ~1hr and then returns the following error:
WARNING: Rolling back the changes to the cluster
Add-AzureRmServiceFabricNodeType : 'accountName' cannot be null.
At line:1 char:1
+ Add-AzureRmServiceFabricNodeType -ResourceGroupName "%ResourceGroupName% ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Add-AzureRmServiceFabricNodeType], ValidationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ServiceFabric.Commands.AddAzureRmServiceFabricNodeType
I have successfully added a nodetype to this cluster in the past, but then i didn't set the -VmSku option. As well as that difference, the subscription has since been upgraded from a pay as you go sub to an Enterprise Agreement. Based on the error received I guess it might have something to do with that, but i can't seem to find what exactly.
Any ideas?
I will assume you used the secure encoding to provide the password
$password = ConvertTo-SecureString -String 'Password$123456' -AsPlainText -Force
I also suggest you add the -Tier as part of your command, because as part of provisioning process it requires the sku, tier and capacity. If you not provide one it will use the default, and the sku might not be compatible with the default tier or your account availability.
You can also check in Azure if the VMSS are created once you run the command.
If you want to investigate further, I would recommend reading the source code for the command operation executed for adding node types.

AWS PowerShell Use-STSRole : The security token included in the request is invalid

In my Jenkins build job I'm using this command to assume an AWS role:
$Creds = (Use-STSRole -Region us-east-1 -RoleArn arn:aws:iam::$IAM_ACCOUNT_ID`:role/$IAM_ROLE -RoleSessionName jenkins).Credentials
I'm getting the following error:
Use-STSRole : The security token included in the request is invalid.
Changing the AWS Role to an invalid role does not change the error message.
It works fine when logging into the server and using the command in Powershell directly.
It also works if I use a AWS CLI command:
aws sts assume-role --role-arn arn:aws:iam::%IAM_ACCOUNT_ID%:role/%IAM_ROLE% --role-session-name jenkins-deploy
Full error message:
Use-STSRole : The security token included in the request is invalid.
At C:\Users\svc-jenkins.WIN-KLBFC355P8D\AppData\Local\Temp\jenkins4822311255190032778.ps1:5 char:11
+ $Creds = (Use-STSRole -Region us-east-1 -RoleArn arn:aws:iam::$e ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...seSTSRoleCmdlet:UseSTSRoleCmdlet) [Use-STSRole], InvalidOperationException
+ FullyQualifiedErrorId : Amazon.SecurityToken.AmazonSecurityTokenServiceException,Amazon.PowerShell.Cmdlets.STS.UseSTSRoleCmdlet
It seems profiles with incorrect credentials where stored in AWS.
These where listed using Get-AWSCredentials:
Get-AWSCredentials -ListStoredCredentials
Then cleared using Remove-AWSCredentialProfile:
Remove-AWSCredentialProfile -ProfileName {MyProfileName}
If using an old version of AWS Powershell Tools you can use Clear-AWSCredentials instead:
Clear-AWSCredentials -ProfileName <String>

Weird Powershell `Set-AWSCredentials` error with INI file

I'm working on an unattended PowerShell script and want to store AWS credentials the Right Way.
According to the documentation, I should be able to store credentials in a .ini file like this
.\myAWSCredentials.ini
[default]
aws_access_key_id = XXXXXXXXXXXXXXX
aws_secret_access_key = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
[namedProfile]
aws_access_key_id = XXXXXXXXXXXXXXX
aws_secret_access_key = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
and load it into my environment with
Set-AWSCredentials -ProfilesLocation .\myAWSCredentials.ini
or
Set-AWSCredentials -ProfileName namedProfile -ProfilesLocation .\myAWSCredentials.ini
But I get an error that doesn't make sense— what does PowerShell have to do with an App.config file?
Set-AWSCredentials : Error loading stored credentials, (profile
location = '.\myAWSCredentials.ini'). Error: App.config does not
contain credentials information. Either add the AWSAccessKey and
AWSSecretKey or AWSProfileName. At line:1 char:1
+ Set-AWSCredentials -ProfilesLocation .\myAWSCredentials.ini
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-AWSCredentials], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Amazon.PowerShell.Common.SetCredentialsCmdlet
Turns out in investigating this, we have a bug in handling the .ini format file in the latest releases (3.1.31.0 onwards) that I'm fixing now.
If you're not using one of these releases (and I don't think you are based on the message, which was fixed in those releases) then try supplying the full path to the credential file to -ProfilesLocation - it could be that the 'current path' as far as PowerShell is concerned isn't what you think it is when the cmdlet runs (I've run into this with other files I've tried to access for example from my profile).
I'll update further when I've fixed the issue.
I think if you fully qualify the path it should work....relative paths are evil.
For example use:
Set-AWSCredentials -ProfilesLocation c:\Path\to\file\myAWSCredentials.ini
easily u can store the credentials by following powershell user guide
Set-AWSCredentials -AccessKey xxxxxxx44Hxxxxxxx -SecretKey WVBUyB5ylBWtpxxxxxxxxxxxxxxxxxxxxxxxxxxx -StoreAs awskeys

How to get rid of error while creating ACS Namespace on Azure Service Bus with PS?

Short story: I get the following error when trying to create a namespace on Azure Service Bus using Azure Powershell (Run as Administrator):
PS C:> New-AzureSBNamespace -Name mynewnamespace2 -Location "East US"
-CreateACSNamespace $true -Namespac New-AzureSBNamespace : Object reference not set to an instance of an object. At line:1 char:1
+ New-AzureSBNamespace -Name mynewnamespace2 -Location "East US" -CreateACSNamespace $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureSBNamespace], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceBus.NewAzureSBNamespaceCommand
Long story: I created a first namespace in Azure Service Bus to use Relay in buffered mode (namespace=mynewnamespace). It works great except when you want to transfer a larger set of data. For this there is the streamed mode and I found this handy example (https://code.msdn.microsoft.com/How-to-send-a-large-c36ab70e), changed appropriate settings for namespace and credentials and ran the server part from the project and I get the error
{"The remote name could not be resolved:
'mynewnamespace-sb.accesscontrol.windows.net'"}
because, of course, this ACS namespace does not exist. So I found out that I need to create the namespace the old fashioned way using PS, installed Azure CLI and run the commands below with the following result:
For a list of all Azure cmdlets type 'get-help azure'.
For a list of Windows Azure Pack cmdlets type 'Get-Command wapack'.
PS C:> azure login
info: Executing command login
|info: To sign in, use a web
browser to open the page https://aka.ms/devicelogin. Enter the code EE226448L to
authenticate. If you're signing in as an Azure AD application, use the
--username and --password parameters.
/info: Added subscription Visual Studio Enterprise with MSDN info: Setting subscription
"Visual Studio Enterprise with MSDN" as default
info: login command OK
PS C:> New-AzureSBNamespace -Name mynewnamespace2 -Location "East US" -CreateACSNamespace $true -NamespaceType Messaging
WARNING: Microsoft Azure PowerShell collects data about how users use
PowerShell cmdlets and some pro encounter. Microsoft uses this
information to improve our PowerShell cmdlets. Participation is volu
choose to participate your device automatically sends information to
Microsoft about how you use Azure Powershell.
If you choose to participate, you can stop at any time by using Azure
PowerShell as follows:
1. Use the Disable-AzureDataCollection cmdlet to turn the feature Off. The cmdlet can be found in the AzureResourceManager module To disable
data collection: PS > Disable-AzureDataCollection
If you choose to not participate, you can enable at any time by using
Azure PowerShell as follows:
1. Use the Enable-AzureDataCollection cmdlet to turn the feature On. The cmdlet can be found in the AzureResourceManager module To enable
data collection: PS > Enable-AzureDataCollection
Select Y to enable data collection [Y/N]: WARNING: You choose not to
participate in Microsoft Azure PowerShell data collection. WARNING:
The setting profile has been saved to the following path
'C:\Users\PDube\AppData\Roaming\Windows Azure Powershell\AzureDataCollectionProfile.json'.
New-AzureSBNamespace :
Object reference not set to an instance of an object. At line:1 char:1
+ New-AzureSBNamespace -Name mynewnamespace2 -Location "East US" -CreateACSNamespace $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureSBNamespace], NullReferenceException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceBus.NewAzureSBNamespaceCommand
I tried to create the new namespace using Azure CLI on 2 different computers, thinking the first install was corrupted, but I get the exact same error.
How can I fix this error?

Security Token Validation Error with JWT token -- HDInsight

I created a new storage account and provisioned an HDInsight cluster on Windows Azure. However, when I try to run any command on Windows Azure Powershell related to the cluster, I get the following error:
PS C:\> Get-AzureHDInsightCluster -Name $clusterName
Get-AzureHDInsightCluster : Request failed with code:Unauthorized
Content:<Error xmlns="http://schemas.microsoft.com/windowsazure"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>AuthenticationFailed</Code><Message>A security token
validation error occured for the received JWT token.</Message></Error>
At line:1 char:1
+ Get-AzureHDInsightCluster -Name $clusterName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureHDInsightCluster], HttpLayerException
+ FullyQualifiedErrorId : Microsoft.Hadoop.Client.HttpLayerException,Microsoft.WindowsAzure.Management.HDInsight.C
mdlet.PSCmdlets.GetAzureHDInsightClusterCmdlet
I'm completely new to HDInsight, but I ran a script before this command to add the Azure account, create variables for the subscription name, storage account name, and container name from this page.
Do you know what this error means? And how to fix it? I'm trying to run a script with Pig commands after following this website.
It looks like the PowerShell environment is not properly setup. You should add your Azure subscription first with GetAzureSubscription. See: http://www.windowsazure.com/en-us/documentation/articles/install-configure-powershell/#Connect