Publishing with curl
This section shows how to use the HTTP client curl to publish Maven artifacts to a CodeArtifact repository.
Publishing artifacts with curl can be useful if you do not have or want to install the Maven
client in your environments.
Publish a Maven artifact with curl
-
Fetch a CodeArtifact authorization token by following the steps in Pass an auth token using an environment variable and return to these steps.
-
Use the following
curlcommand to publish the JAR to a CodeArtifact repository:In each of the
curlcommands in this procedure, replace the following placeholders:Replace
my_domainwith your CodeArtifact domain name.Replace
111122223333with the ID of the owner of your CodeArtifact domain.Replace
us-west-2with the region in which your CodeArtifact domain is located.Replace
my_repowith your CodeArtifact repository name.
curl --request PUT https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/maven/my_repo/com/mycompany/app/my-app/1.0/my-app-1.0.jar\ --user "aws:$CODEARTIFACT_AUTH_TOKEN" --header "Content-Type: application/octet-stream" \ --data-binary @my-app-1.0.jarImportant
You must prefix the value of the
--data-binaryparameter with a@character. When putting the value in quotation marks, the@must be included inside the quotation marks. -
Use the following
curlcommand to publish the POM to a CodeArtifact repository:curl --request PUT https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/maven/my_repo/com/mycompany/app/my-app/1.0/my-app-1.0.pom\ --user "aws:$CODEARTIFACT_AUTH_TOKEN" --header "Content-Type: application/octet-stream" \ --data-binary @my-app-1.0.pom -
At this point, the Maven artifact will be in your CodeArtifact repository with a status of
Unfinished. To be able to consume the package, it must be in thePublishedstate. You can move the package fromUnfinishedtoPublishedby either uploading amaven-metadata.xmlfile to your package, or calling the UpdatePackageVersionsStatus API to change the status.-
Option 1: Use the following
curlcommand to add amaven-metadata.xmlfile to your package:curl --request PUT https://my_domain-111122223333.d.codeartifact.region.amazonaws.com/maven/my_repo/com/mycompany/app/my-app/maven-metadata.xml\ --user "aws:$CODEARTIFACT_AUTH_TOKEN" --header "Content-Type: application/octet-stream" \ --data-binary @maven-metadata.xmlThe following is an example of the contents of a
maven-metadata.xmlfile:<metadata modelVersion="1.1.0"> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <versioning> <latest>1.0</latest> <release>1.0</release> <versions> <version>1.0</version> </versions> <lastUpdated>20200731090423</lastUpdated> </versioning> </metadata> -
Option 2: Update the package status to
Publishedwith theUpdatePackageVersionsStatusAPI.aws codeartifact update-package-versions-status \ --domainmy_domain\ --domain-owner111122223333\ --repositorymy_repo\ --format maven \ --namespacecom.mycompany.app\ --packagemy-app\ --versions1.0\ --target-status Published
-
If you only have an artifact's JAR file, you can publish a consumable package version to a CodeArtifact repository using mvn. This can be useful if you do not have
access to the artifact's source code or POM. See Publish third-party artifacts for details.