簡體   English   中英

AWS Cloudformation:無法在 cfn-init 或 UserData 中訪問網絡共享驅動器

[英]AWS Cloudformation: Network Share Drive is inaccessible in cfn-init or UserData

在 cloudformation 中啟動 EC2 實例時,我試圖從 a.network 共享驅動器復制文件:

Resources:
     MigrationInstance:
        Type: 'AWS::EC2::Instance'
        Properties:
          ...
          UserData:
            Fn::Base64: !Sub |
              <powershell>
              New-Item "C:\migratedFiles" -itemType Directory

              #Copy-Item -Path \\192.168.41.103\shared\* -Destination C:\migratedFiles -Recurse -Force # also don't work

              cfn-init.exe --verbose --stack ${AWS::StackName} --resource MigrationInstance --region ${AWS::Region}
              </powershell>
              <persist>true</persist>
        Metadata: 
          AWS::CloudFormation::Init: 
            config:
              files:
                C:\windows\temp\copyfiles.ps1:
                  content: !Sub |
                    $sourcePathExist = Test-Path \\192.168.41.103\shared
                    if($sourcePathExist) #this is always false
                    {
                      # Copy-Item -Path \\192.168.41.103\shared\* -Destination C:\migratedFiles -Recurse -Force
                      xcopy \\192.168.41.103\shared C:\migratedFiles /E /H /C /I
                      
                      Write-Output "Migrate files success"
                    }
                    else 
                    {
                        Write-Warning "Migrate files failed"
                    }
                    
              commands:
                1-RunCopyFiles:
                  command:
                    powershell.exe -executionpolicy bypass -file "C:\windows\temp\copyfiles.ps1"
                  waitAfterCompletion: 'forever'

但似乎在cfn-init中無法訪問共享文件夾,因為Test-Path \\192.168.41.103\shared返回false ..

但是當我在 EC2 實例中手動運行Test-Path時 - 它返回true並且xcopy命令有效

xcopy \\192.168.41.103\shared C:\migratedFiles /E /H /C /I

在我看來,共享驅動器在UserDatacfn-init中不可訪問。 但是,當您通過 SSM 進入實例並在那里手動運行命令時,它是可以訪問的( xcopy有效並且test-path返回true )。 我想知道為什么會這樣?

所以事實證明實例需要加入 AD 域。 但仍然令人困惑為什么我可以手動從 Ec2 訪問它,即使它沒有加入域。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM