Skip to content

Commit

Permalink
fix: Resource limit on preview envs
Browse files Browse the repository at this point in the history
  • Loading branch information
aweiland committed Jun 7, 2024
1 parent cc5ab85 commit 89d239b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
17 changes: 17 additions & 0 deletions copilot/environments/overrides/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Overriding Copilot generated CloudFormation templates with YAML Patches

The file `cfn.patches.yml` contains a list of YAML/JSON patches to apply to
your template before AWS Copilot deploys it.

To view examples and an explanation of how YAML patches work, check out the [documentation](https://aws.github.io/copilot-cli/docs/developing/overrides/yamlpatch).

Note only [`add`](https://www.rfc-editor.org/rfc/rfc6902#section-4.1),
[`remove`](https://www.rfc-editor.org/rfc/rfc6902#section-4.2), and
[`replace`](https://www.rfc-editor.org/rfc/rfc6902#section-4.3)
operations are supported by Copilot.
Patches are applied in the order specified in the file.

## Troubleshooting

* `copilot [noun] package` preview the transformed template by writing to stdout.
* `copilot [noun] package --diff` show the difference against the template deployed in your environment.
21 changes: 21 additions & 0 deletions copilot/environments/overrides/cfn.patches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Delete the task role resource
# - op: remove
# path: /Resources/TaskRole

# Add a service connect alias
# - op: add
# path: /Resources/Service/Properties/ServiceConnectConfiguration/Services/0/ClientAliases/-
# value:
# Port: !Ref TargetPort
# DnsName: yamlpatchiscool

# Replace the task role in the task definition
# - op: replace
# path: /Resources/TaskDefinition/Properties/TaskRoleArn
# value: arn:aws:iam::123456789012:role/MyTaskRole

# Only 10 policies allowed per account. Hard limit.
# A shared policy is created via terraform
# https://github.com/aws/copilot-cli/issues/5743#issuecomment-2022882367
- op: remove
path: /Resources/LogResourcePolicy
15 changes: 13 additions & 2 deletions copilot/scripts/env-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
. ${SCRIPT_DIR}/funcs.sh

#copilot svc show -n mindlogger-backend --json | jq -r '.configurations[] | select( .environment | contains("pr-1393") ) | .environment'
#copilot svc show -n mindlogger-backend --json | jq -r '.configurations[] | select( .environment | contains("pr-1302") ) | .environment'

#Create environment only once
if copilot env ls -a "$APP_NAME" | grep -q "$ENV_NAME"; then
echo "Environment already exists"
exit 0
echo "Environment already exists, checking status"
ENV_CHECK=$(copilot svc show -n mindlogger-backend --json | jq -r ".configurations[] | select( .environment | contains(\"$ENV_NAME\") ) | .environment")

if [ -z "${ENV_CHECK}" ]; then
echo "Service does not exist, rebuilding..."
${SCRIPT_DIR}/env-stop.sh
else
echo "Status good, continuing..."
exit 0
fi
else
if [ "$ENV_NAME" == 'feature' ]; then
echo "You must create feature from bootstrap script locally"
Expand Down

0 comments on commit 89d239b

Please sign in to comment.