Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use other CloudFormation stack outputs as env variables in my ECS tasks #13370

Closed
asungomez opened this issue Oct 26, 2023 · 2 comments
Closed
Labels
containers Issues related to the non-serverless container based functionality pending-triage Issue is pending triage question General question

Comments

@asungomez
Copy link

asungomez commented Oct 26, 2023

Amplify CLI Version

12.7.1

Question

Hi all!

I've created an API as a serverless container in Fargate using the Amplify CLI. All is good and works. Then I want to set up a DocumentDB for data storage (I need Mongo compatibility, cannot do the default DynamoDB). I've created a custom resource with the stack that creates my cluster, my instances, and a secret in the Secrets Manager with the credentials. The stack outputs are the Cluster endpoint, Cluster port, and Secret ARN.

I would like to inject these 3 values into my Fargate container as environment variables. Here's what I've tried so far:

  • Adding them as parameters to the API CF stack: not sure if it's possible. Can't do it through the CLI using the "Access other resources" option, and do not want to do it through the team-provider file because that would mean hardcoding the values, and that's not what I want.
  • Adding the Cluster, Instance, and Secret to the API stack as extra resources, so I can reference them directly. They get deleted every time I amplify push (I assume the stack gets regenerated from the docker-compose and overrides any changes I make).

Is there anything else I can try?

Edit: I've managed to inject the parameters into the stack by adding them to the backend-config.json and to the amplify-meta.json, into the dependsOn array, like this:

  "MyAPI": {
      "apiType": "REST",
      "build": true,
      "dependsOn": [
        {
          "attributes": [
            "ClusterName",
            "VpcId",
            "VpcCidrBlock",
            "SubnetIds",
            "VpcLinkId",
            "CloudMapNamespaceId"
          ],
          "category": "",
          "resourceName": "NetworkStack"
        },
        {
          "attributes": [
            "ClusterEndpoint",
            "ClusterPort",
            "PasswordSecretArn"
          ],
          "category": "",
          "resourceName": "customDatabase"
        }
      ],
      "deploymentMechanism": "FULLY_MANAGED",
      "iamAccessUnavailable": true,
      "imageSource": {
        "type": "CUSTOM"
      },
      "providerPlugin": "awscloudformation",
      "resourceName": "graphql",
      "restrictAccess": false,
      "service": "ElasticContainer",
      "skipHashing": false
    }

Now I have them in the CF stack:

    "customDatabaseClusterEndpoint": {
      "Type": "String"
    },
    "customDatabaseClusterPort": {
      "Type": "String"
    },
    "customDatabasePasswordSecretArn": {
      "Type": "String"
    },

But every time I try to reference them from the container definition:

        "ContainerDefinitions": [
          {
            "Command": [],
            "EntryPoint": [],
            "Environment": [
              {
                "Name": "DB_ENDPOINT",
                "Value": {
                  "Ref": "customDatabaseClusterEndpoint"
                }
              }
            ],

It gets overriden by the amplify push command

@asungomez asungomez added pending-triage Issue is pending triage question General question labels Oct 26, 2023
@ykethan ykethan added the containers Issues related to the non-serverless container based functionality label Oct 26, 2023
@ykethan
Copy link
Member

ykethan commented Oct 26, 2023

Hey @asungomez, thank you for reaching out. The issue appears to be similar to feature request #7049. Utilizing custom resource outputs into a different resource such as API is currently not supported.
Closing the issue as duplicate, please feel free in adding a thumbs up to the feature request.

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Issues related to the non-serverless container based functionality pending-triage Issue is pending triage question General question
Projects
None yet
Development

No branches or pull requests

2 participants