amazon-web-services - AWS 云信息 : Network Share Drive is inaccessible in cfn-init or UserData

标签 amazon-web-services amazon-ec2 aws-cloudformation

我尝试在 cloudformation 中启动 EC2 实例时从网络共享驱动器复制文件:

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:\migeratedFiles/E/H/C/I

在我看来,在 UserDatacfn-init 中无法访问共享驱动器。但是,当您 SSM 进入实例并手动运行命令时,它是可以访问的(xcopy 工作并且 test-path 返回 true)。我想知道为什么会这样?

最佳答案

原来实例需要加入AD域。但仍然令人困惑的是为什么我可以从 Ec2 手动访问它,即使它没有加入域。

关于amazon-web-services - AWS 云信息 : Network Share Drive is inaccessible in cfn-init or UserData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74397764/

相关文章:

amazon-web-services - kubernetes + coreos 集群 - 替换证书

configuration - 使用子域配置 Nginx

regex - cloudformation IAM 策略名称的正则表达式是什么

amazon-web-services - 如何在多个 AWS Lambda 函数之间共享数据?

javascript - 即时创建带有策略和证书的 AWS IoT "things"

ubuntu - 从安装了 ubuntu-desktop 的 Ubuntu 18.04 构建的 EC2 AMI 无法访问

amazon-web-services - AmazonRDSEnhancedMonitoringRole 的 Cloudformation 模板

docker - 尝试设置新的 ECS 集群时,容器正在连接默认集群

amazon-web-services - 如何从 CloudFormation 模板中获取 AWS IOT 端点 URL?

amazon-ec2 - Amazon EC2 预留实例能否与 AWS Elastic Beanstalk 中的自动扩展一起使用?