Pulumi project that deploys to ECS with a Cloudfront CDN and uses a component resource.
- Create an empty repo and clone it.
- In the repo folder, run
pulumi new https://github.com/MitchGerdischOrg/aws-ecs-cloudfront-template- You are prompted for the project name, description, stack name, and
agentPoolId. agentPoolIdis the Pulumi Deployments agent pool ID to run deployments on. Accept the default,pulumi-provided-runners, to use Pulumi Cloud hosted runners.- Change it later with
pulumi config set agentPoolId <value>.
- You are prompted for the project name, description, stack name, and
The repo contains two component resource packages in separate folders. One abstracts the code for setting up the image, ECR and ECS deployment and the other abstracts the deploymnt settings. Although the components can can be used as locally referenced components, for this exercise, we will work with them as component packages.
Initially, we will install them as local component packages, but later discuss managing them in git repos with semantic versioning.
From the Pulumi project folder (where pulumi new created the project), run pulumi package add to install and set up the two component resource packages.
-
Run
pulumi package add ./component-aws-container-services -
Run
pulumi package add ./component-pulumi-deployment-settings
The pulumi package add command performs the following tasks:
- It adds a packages directive to the
Pulumi.yamlfile. - It creates an
sdksfolder. - It updates
requirements.txtor similar with the path to the SDKs. - It provides the import lines for the generated SDKs.
- ADD The import lines to
__main__.py.
- ADD The import lines to
SUBSEQUENTLY, you only need to run pulumi install which will use the packages directive in Pulumi.yaml to generate the local SDKs
You can skip these steps initially, and jump down to "Deploying the Stack" below.
But, to better adopt centrally managed component packages, you can move the components into their own git repos and enable versioning and more centralized management of the components. If you do so, the Pulumi project code will need to be updated with the proper packages references and related sdk names.
So after moving the components to git repos, you will want to run pulumi package add again but point it at the github repo.
For example: pulumi package add https://GITREPO-PATH-TO-COMPONENT/component-aws-container-services
and similarly for the deployment-settings component.
As before the pulumi package add command will udpate Pulumi.yaml and provide the import lines for __main__.py. You will need to clean up Pulumi.yaml to remove the local component references and update __main__.py with the new import lines.
Once the components are in their own repos, you can set up versioning for the components:
- Tag the repo with version(s) of the form
vX.Y.Z. - In the
packagesdirective inPulumi.yamladd@vX.Y.Zto use the specific version of the component. - Run
pulumi installbeforepulumi upto udpate to the given version.
You can also publish the package to the Pulumi Cloud component registry to be able to track usage of the and auto generate API docs.
- Publish the package:
pulumi package publish GITREPO_PATH_TO_COMPONENNT --publisher PULUMI_ORG_NAME- Where
GITREPO_PATH_TO_COMPONENTis the same path used for thepulumi package addcommand. - Where
PULUMI_ORG_NAMEis the name of your Pulumi org.
- Where
Whereever pulumi up is run (laptop, deployment runner, etc) the following needs to be available:
- docker is running: Used to build the image pushed to ECR and deployed to ECS.
- AWS credentials/access with applicable permissions.
- Your preferred python tooling is available.
This project is set up such that it requires an initial pulumi up from a laptop to bootstrap the deployment settings using the deployment settings component resource. In production, the deployment settings could be managed by a completely separate stack that manages the deployment settings for multiple stacks using the same sort of logic captured in the component resource. But for ease of use, this initial boostrapping approach is used.
pulumi install
pulumi upBE SURE to push the code to the repo you created for the new project before trying to run from Pulumi deployments.
From the Pulumi UI, use the Actions button in the upper right when viewing the stack to run udpates, previews, etc.
You can also set things up to run deployments automatically for various conditions:
- Scheduled events such as drift detection or shut down, etc.
- Run previews when a PR is created.
- Run updates when a PR is merged.