Creating CodeArtifact resources with AWS CloudFormation
CodeArtifact is integrated with AWS CloudFormation, a service that helps you model and set up your AWS resources so that you can spend less time creating and managing your resources and infrastructure. You create a template that describes all the AWS resources that you want, and AWS CloudFormation takes care of provisioning and configuring those resources for you.
When you use AWS CloudFormation, you can reuse your template to set up your CodeArtifact resources consistently and repeatedly. Just describe your resources once and then provision the same resources over and over in multiple accounts and AWS Regions.
CodeArtifact and AWS CloudFormation templates
To provision and configure resources for CodeArtifact and related services, you must understand AWS CloudFormation templates. Templates are formatted text files in JSON or YAML. These templates describe the resources that you want to provision in your AWS CloudFormation stacks. If you're unfamiliar with JSON or YAML, you can use AWS CloudFormation Designer to help you get started with AWS CloudFormation templates. For more information, see What is AWS CloudFormation Designer? in the AWS CloudFormation User Guide.
CodeArtifact supports creating domains, repositories, and package groups in AWS CloudFormation. For more information, including examples of JSON and YAML templates, see the following topics in the AWS CloudFormation User Guide:
Preventing deletion of CodeArtifact resources
CodeArtifact repositories contain critical aplication dependencies that may not be easy to recreate
if lost. To protect CodeArtifact resources against accidential deletion when managing CodeArtifact resources with CloudFormation,
include the DeletionPolicy
and UpdateRetainPolicy
attributes with a value of Retain
on
all domains and
respositories. This will prevent deletion if the resource is removed from the stack template, or the entire stack is
accidentially deleted. The following YAML snippet shows a basic domain and repository with these attributes:
Resources: MyCodeArtifactDomain: Type: 'AWS::CodeArtifact::Domain' DeletionPolicy: Retain UpdateReplacePolicy: Retain Properties: DomainName: "my-domain" MyCodeArtifactRepository: Type: 'AWS::CodeArtifact::Repository' DeletionPolicy: Retain UpdateReplacePolicy: Retain Properties: RepositoryName: "my-repo" DomainName: !GetAtt MyCodeArtifactDomain.Name
For more information about these attributes, see DeletionPolicy and UpdateReplacePolicy in the AWS CloudFormation User Guide.
Learn more about AWS CloudFormation
To learn more about AWS CloudFormation, see the following resources: