Azure DevOps管道运行AWSPowerShellModuleScript@1任务报错求助
Let's tackle this problem head-on—you're hitting two key issues here: your build agent can't download the NuGet package provider (blocking it from finding the AWSPowerShell module), and honestly, you might not even need that AWSPowerShellModuleScript@1 task for your Serverless Framework deployment. Here's how to resolve this:
1. Replace the AWSPowerShellModuleScript@1 Task (You Don't Need It)
Your inline script is just running npx serverless --package dev_artifacts—this is a Node.js/Serverless CLI command, not AWS PowerShell-specific cmdlets. The AWSPowerShellModuleScript@1 task is designed for running AWS PowerShell commands, not Serverless deployments.
Instead, use a standard PowerShell task paired with the AWS CLI task to handle credentials. Serverless Framework automatically reads AWS credentials from the local AWS config file or environment variables:
# Remove the AWSPowerShellModuleScript@1 task and replace it with these steps - task: AWSCLI@2 displayName: Configure AWS Credentials for Serverless inputs: awsCredentials: '###' # Use your existing AWS service connection regionName: '###' # Your target AWS region command: 'configure' configureParameters: 'set aws.access_key_id $(AWS_ACCESS_KEY_ID) && set aws.secret_access_key $(AWS_SECRET_ACCESS_KEY) && set aws.region $(AWS_REGION)' - task: PowerShell@2 displayName: Deploy to Lambda@Edge via Serverless inputs: targetType: 'inline' script: | # Navigate to your project root (where serverless.yml is located) cd $(Build.SourcesDirectory) # Run Serverless deploy with the correct package path npx serverless deploy --package $(Build.ArtifactStagingDirectory)
2. Fix the NuGet Provider Issue (If You Need AWSPowerShell Later)
If you do require the AWSPowerShell module for other pipeline steps, the error stems from your agent being unable to download the NuGet package provider (likely due to network restrictions or an untrusted PSGallery repository). Add this step before any AWSPowerShell tasks:
- task: PowerShell@2 displayName: Prepare PSGallery and NuGet Provider inputs: targetType: 'inline' script: | # Mark the PSGallery repository as trusted (required to install modules) Set-PSRepository -Name PSGallery -InstallationPolicy Trusted # Force-install the NuGet package provider Install-PackageProvider -Name NuGet -Force -Scope CurrentUser # Install the AWSPowerShell module explicitly Install-Module -Name AWSPowerShell -Force -Scope CurrentUser -AllowClobber
3. Verify Your Package Path
Double-check that your CopyFiles@2 task is outputting files to the right location. Your current setup copies build/** to $(Build.ArtifactStagingDirectory)—ensure the --package argument in your Serverless command points to this exact directory (not dev_artifacts, since that's the artifact name, not the path to the build files).
内容的提问来源于stack exchange,提问作者Damian Jacobs

