[英]AWS Cloudformation: Network Share Drive is inaccessible in cfn-init or UserData
I am trying to copy files from a.network share drive upon launching the EC2 instance in cloudformation:在 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'
But it seems like the shared folder is not accessible in cfn-init
as Test-Path \\192.168.41.103\shared
returns false
..但似乎在
cfn-init
中无法访问共享文件夹,因为Test-Path \\192.168.41.103\shared
返回false
..
But when I manually run the Test-Path
in the EC2 instance - it returns true
and the xcopy
command works但是当我在 EC2 实例中手动运行
Test-Path
时 - 它返回true
并且xcopy
命令有效
xcopy \\192.168.41.103\shared C:\migratedFiles /E /H /C /I
It seems to me that the shared drive is not accessible in UserData
and cfn-init
.在我看来,共享驱动器在
UserData
和cfn-init
中不可访问。 But it is accessible when you SSM into the instance and manually run the command there (the xcopy
works and the test-path
returns true
).但是,当您通过 SSM 进入实例并在那里手动运行命令时,它是可以访问的(
xcopy
有效并且test-path
返回true
)。 I wonder why is this the case?我想知道为什么会这样?
So it turns out the instance need to be joined to the AD domain.所以事实证明实例需要加入 AD 域。 But still confusing why I can access it from Ec2 manually even if its not domain joined.
但仍然令人困惑为什么我可以手动从 Ec2 访问它,即使它没有加入域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.