Possible bug in CodeArtifact PowerShell command Publish-CAPackageVersion

0

I successfully published a zip file to CodeArtifact using the AWS CLI:

aws codeartifact publish-package-version --domain my-domain --repository my-builds --format generic --namespace my-space --package AppName --package-version 3.53.62 --asset-content <file  on my computer> --asset-name AppName.3.53.62.zip --asset-sha256  <my file hash>

I deleted the package from CodeArtifact and tried to re-publish using PowerShell:

Publish-CAPackageVersion -Domain my-domain -Repository my-builds -Format generic -Namespace my-space -Package AppName -PackageVersion 3.53.62 -AssetContent <file on my computer> -AssetName AppName.3.53.62.zip -AssetSHA256  <my file hash>

The result indicated success, but the package in CodeArtifact had issues. It was only about 100 bytes in size when it should have been about 5MB. The package could not be successfully fetched from CodeArtifact.

aws-cli version: 2.13.4 AWS PowerShell version: 4.1.323

질문됨 6달 전204회 조회
1개 답변
0
수락된 답변

Can you please provide a complete example and more details to help identify what may have gone wrong? In particular:

  1. How are you providing <file on my computer> and <my file hash>?
  2. "The package could not be successfully fetched from CodeArtifact." - What do you mean by this? A smaller than expected file came back, or you saw an error?

I was just able to test this successfully. One possibility is that you provided a file path for the AssetContent parameter, expecting similar behavior as the aws cli. If you provided a path string (like 'C:\some-file.txt'), then the content of that string is what will be saved as the asset file, not the contents of the file at that path. That could explain the small asset size. Here is a working example that provides a FileInfo object to AssetContent (string, string[], System.IO.FileInfo or System.IO.Stream are acceptable types per these docs).

$AssetFilePath = 'C:\some-file.txt'
$AssetFile = ([System.IO.FileInfo]$AssetFilePath)
$AssetSHA256 = (Get-FileHash -Path $AssetFile -Algorithm SHA256).Hash

Publish-CAPackageVersion
    -Domain test-domain
    -Repository test-repository
    -Format generic
    -Namespace test-ns
    -Package test-generic-package
    -PackageVersion 1.0.0
    -AssetContent $AssetFile
    -AssetName some-file.txt
    -AssetSHA256 $AssetSHA256
답변함 6달 전
profile picture
전문가
검토됨 한 달 전
  • That did the trick. Thank you so much Brian! I missed that the asset content had to be of type FileInfo.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠