LoginSignup
1
1

More than 1 year has passed since last update.

sam initがWindowsで失敗する場合はパスの文字列設定の上限を変更する。

Posted at

IntellJでSAM Applicationを作成しようとしたときに引っかかったのでメモする

起きた事象

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 in C:\Users\masas\AppData\Roaming\AWS SAM directory or file an issue at h
ttps://github.com/aws/aws-sam-cli/issues

エクスプローラーからファイルのパーミッションをいじっても変化がなし

原因はパーミッションではなくWindowsのパスの上限が260文字にデフォルトの制限に引っかかりファイルが認識できないことらしい

解消方法

PowerShellでLongPathsEnabledの設定をすることで解消できる。

PowerShellを管理者モードで開き以下をコマンドを実行

PS C:\Windows\system32> New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
>> >> -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

以下のようにコマンドが通れば正常完了

C:\Users\masas\IdeaProjects\untitled1>sam init 

You can preselect a particular runtime or package type when using the `sam init` experience.
Call `sam init --help` to learn more.

Which template source would you like to use?
        1 - AWS Quick Start Templates
        2 - Custom Template Location
Choice: 1

Choose an AWS Quick Start application template
        1 - Hello World Example
        2 - Multi-step workflow
        3 - Serverless API
        4 - Scheduled task
        5 - Standalone function
        6 - Data processing
        7 - Infrastructure event management
        8 - Serverless Connector Hello World Example
        9 - Multi-step workflow with Connectors
        10 - Lambda EFS example
        11 - Machine Learning
Template: 1

Use the most popular runtime and package type? (Python and zip) [y/N]: y

Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: N

Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]:

Project name [sam-app]:


Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment)

    -----------------------
    Generating application:
    -----------------------
    Name: sam-app
    Runtime: python3.9
    Architectures: x86_64
    Dependency Manager: pip
    Application Template: hello-world
    Output Directory: .

    Next steps can be found in the README file at ./sam-app/README.md


    Commands you can use next
    =========================
    [*] Create pipeline: cd sam-app && sam pipeline init --bootstrap
    [*] Validate SAM template: cd sam-app && sam validate
    [*] Test Function in the Cloud: cd sam-app && sam sync --stack-name {stack-name} --watch

参考リンク

パスの最大長の制限(Microsoft)
sam init quickstart templates failing on windows #4031
【SAM + Cognito + Amplify ライブラリでログイン機能を実装した React アプリを作成】Part1 - SAM で API 作成

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1