Unable to get AWS powershell comands working in Windows-10 - amazon-web-services

I want to run some AWS commands using PowerShell scripts in windows. I went ahead and ran this below command.
Install-Module AWSPowerShell
The module got installed without any error. But I'm getting below error when I try to do "Set-AWSCredentials"
Can anyone please help me understand what I'm doing wrong here?

I think you should try to import the module installed. Almost you can use the following command Get-Module to check if the module is imported and installed in the current session of powershell execution.
Import-Module AWSPowerShell
Get-Module -ListAvailable

adding -Force solved it for me where "Import-Module AWSPowerShell" still showed no effect.
Import-Module AWSPowerShell -Force

Related

Issue with assembly AWSSDK.WorkSpaces when trying to restore workspace

I am using the below powershell command to restore a workspace and seeing the error below:
Restore-WKSWorkspace -WorkspaceId <WorkspaceId> -EndpointUrl <Endpoint URL> -ProfileName <ProfileName> -Region <Region> -Force
Error:
Could not load type 'Amazon.WorkSpaces.Model.RestoreWorkspaceResponse' from assembly 'AWSSDK.WorkSpaces, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604'
I have tried updating the module AWS.Tools.WorkSpaces and AWSPowerShell, but no luck. Tried re-opening powershell and importing the modules and still the same error.
Any suggestions please on how to fix this problem?

AWS Serverless Application Model init error on Pycharm

I am trying to create a new AWS Serverless Application on Pycharm but i am getting this error:
Could not execute `sam init`!: [Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment),
Error: Unstable state when updating repo. Check that you have permissions to create/delete files
How can i solve this problem ?
Details:
OS:Windows 10 , x64
Version: Python 3.9, SAM CLI- 1.53.0
IDE: Pycharm 2022.1.3 Pro Edition
Git Version 2.37
Open PowerShell in admin mode and type this and execute
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
worked for me. (fixes webstorm aws toolkit error in init too)
Okay here is the problem why it occurs and the solution for Windows users:
The problem was with the path ("AWS SAM") in Windows that has a space causes the problem:
By calling the --location arg and puting the full path in double quotes it works
sam init --location "C:\Users[your_user_name]\AppData\Roaming\AWS
SAM\aws-sam-cli-app-templates\python3.9\cookiecutter-aws-sam-hello-python"
Ref: https://github.com/aws/aws-sam-cli/issues/1891
Thanks to:
https://github.com/hawflau
https://github.com/john-zenden
On my windows machine, I fixed it by setting LongPathsEnabled to 1 in the registery:
Open Registry Editor (regedit.exe).
Navigate to
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
Set LongPathsEnabled to 1.
This sets Git to allow long paths
Neither of the solutions worked for me. Instead:
Open Registry Editor (regedit.exe).
Navigate to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
Set LongPathsEnabled to 1
Copied from: https://lightrun.com/answers/aws-aws-sam-cli-permissions-error-unstable-state-when-updating-repo
Run this in powershell (as admin)
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
works for me

command "amplify configure" can not run due to amplify.ps1 security issue

I am using aws amplify and am trying to run the command "amplify configure" in my root directory but keep getting this error response
amplify : File C:\Users\munet\AppData\Roaming\npm\amplify.ps1 cannot be loaded. The file C:\Users\munet\AppData\Roaming\npm\amplify.ps1 is
not digitally signed. You cannot run this script on the current
system. For more information about running scripts and setting
execution policy, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1
amplify configure
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
I tried unblocking the file in powershell but it still displays the same error. I even went to the file in my AppData folder, clicked properties and the check to mark unblock was not an option. I am wondering what else it could be that is preventing this file from being run. I am thinking I have to digitally sign the script but am unsure where to. Here is a link to where the solution may possibly be. I will upload the solution if I find. Thanks.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1#remotesigned
The solution to this problem is rather simple. You're running this command in Powershell. Sometimes it can help to run powershell as an administrator but the best solution is just to run it in Command Prompt (cmd)
You can also bypass that security check by running this command:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
Or just use:
set-ExecutionPolicy RemoteSigned -Scope CurrentUser
But not both as they will conflict between each other

Amplify configure

I have installed 'amplify-cli'. When I type 'amplify configure', I get the error message:
'amplify is not recognized as an internal or external command, operable program or batch file'.
Please share your platform. Are you developing on Linux, Windows (Powershell), or Linux on Windows (WSL/Ubuntu)?
Did you install the CLI globally?
Try this:
npm install -g #aws-amplify/cli
And see if that works. If the global install fails, you can try running this per an Amplify developer:
npm install -g #aws-amplify/cli --unsafe-perm=true
Edit: since you're on Windows, it's possible the CLI wasn't added to your $PATH variable. You can fix it by seeing this Github issue.
To solve this, simply edit a PATH key under system Environment Variables and add a new path pointing to amplify:
C:\Users\{UserName}\AppData\Roaming\npm\amplify.cmd
If you have globally installed amplify/cli then you should find two files named amplify and amplify.cmd in the above mentioned npm directory.
Under same circumstances I run all the suggested solutions on Windows 10 machine (64 bit). None of them seemed to do the trick.
I got a more specific error:
..... cannot be loaded because running scripts is disabled on this
system .... + CategoryInfo : SecurityError: (:) [],
PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
The issue appears due to Windows PowerShell execution policies. Eventually, I managed to amend it by applying the following:
C:\Windows\System32>powershell Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Above solutions didn't work for me, I had to run this instead of 'amplify init':
C:\Users{UserName}\AppData\Roaming\npm\amplify init
I had the same issue and my problem was because I was trying to install it using
yarn global add #aws-amplify/cli
Apparently, it doesn't work when it is installed with yarn it has to be npm. It's funny because there are no errors shown. There might be a fix to it maybe someone can look into that.
If you are on windows platform avoid using the global(-g) flag from your npm command. Install Amplify CLI with below npm command.
npm install #aws-amplify/cli
It worked for me.
Error:
amplify : The term 'amplify' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. le program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
amplify init
CategoryInfo : ObjectNotFound: (amplify:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
Try this for windows:
Step 1:
npm install -g #aws-amplify/cli --unsafe-perm=true
Step 2:
npm config get prefix
Step 3:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
you must run this code on PowerShell not a cmd.
I had the same issue
For Windows, try the below command to install Amplify CLI
$ curl -sL https://aws-amplify.github.io/amplify-cli/install-win -o
install.cmd && install.cmd
$ amplify configure
for more info on installation follow the link
https://docs.amplify.aws/cli/start/install/

Setup git via windows docker file

I write Dockerfile which is based on windowsnanoserver. I need to add to this image git. In order to achieve it I did the following:
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/Git-2.12.2.2-64-bit.exe'
RUN Invoke-Expression "c:\Git-2.12.2.2-64-bit.exe"
But when I execute this lines via docker build, I receive following error message:
Invoke-Expression : The term 'c:\Git-2.12.2.2-64-bit.exe' is not
recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
I realize that this error message indicates that due to console nature of windows docker images I'll not be able to execute GUI installers. Unfortunately git doesn't have console installer. Chocolatey works fine under windowsservercore image but doesn't work at windowsnanoserver. In order to install git for windowsnanoserver I have idea to repeat in Dockerfile commands from chocolatey git installer which is fine for me, but still I'd like to know is there any simpler way to install git on windowsnanoserver?
I've solved issue with GUI through usage of MinGit and by putting information about mingit into environment/path variable. I've used following approach:
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.12.2.windows.2/MinGit-2.12.2.2-64-bit.zip' -OutFile MinGit.zip
RUN Expand-Archive c:\MinGit.zip -DestinationPath c:\MinGit; \
$env:PATH = $env:PATH + ';C:\MinGit\cmd\;C:\MinGit\cmd'; \
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name Path -Value $env:PATH
You are correct, both Windows and Linux containers generally focus on running headless applications (i.e. without GUI).
It sounds like you want to create a container image based on the nanoserver image that has git?
Chocolatey is a great idea.
If you give me the broader context of your goals I can help you further.
Cheers :)
Installing to the docker image using Chocolatey worked for me as per this image: ehong
I addeded these lines to my Dockerfile:
ENV ChocolateyUseWindowsCompression false
RUN powershell Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
RUN choco install git.install -y --no-progress
Call the git.setup.exe installation file with the parameters /? to list all possible switches.
To run a silent installation:
git.setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS
To do a customized installation:
run manually git installation with the parameter /SAVEINF="filename"
e.g:. git-2.xx.exe /SAVEINF="filename"
And then to repeat the installation with /LOADINF="filename"
e.g.: git.setup.exe /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /LOADINF="filename"
It's documented on:
Git: Silent-or-Unattended-Installation
You can download and use the Git Thumbdrive edition:
https://git-scm.com/download/win
look for the link under:
Git for Windows Portable ("thumbdrive edition")
E.G.: https://github.com/git-for-windows/git/releases/download/v2.23.0.windows.1/PortableGit-2.23.0-64-bit.7z.exe
Based on the answer of #Mariusz, the following lines install git into Windows image
# copy inf file
COPY resources/git-install.inf c:\git-install.inf
# get Git install file
RUN Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.30.1.windows.1/Git-2.30.1-64-bit.exe' -OutFile 'git.exe'; `
# install Git
Start-Process "c:\git.exe" -ArgumentList '/SP-', '/VERYSILENT', '/NORESTART', '/NOCANCEL', '/CLOSEAPPLICATIONS', '/RESTARTAPPLICATIONS', '/LOADINF=git-install.inf' -Wait -NoNewWindow; `
# delete files
Remove-Item -Force git-install.inf; `
Remove-Item -Force git.exe;