Referencing parameters



When building a cloud architecture with multiple resources, those resources often need to communicate with each other. To do so, they require identifiers such as a database endpoint, an API Gateway URL, or an ARN. These identifiers are assigned dynamically and cannot be known before the stack is deployed.

Stacktape allows you to dynamically reference these resources using the $ResourceParam() and $CfResourceParam() directives.

Parameters of Stacktape resources

You can reference the most commonly needed parameters of Stacktape-managed resources, such as database endpoints, database connection strings, and URLs of API Gateways and Load Balancers.

These parameters can be referenced using the $ResourceParam() directive, which takes two arguments:

resources:
  myDatabase:
    type: relational-database
    properties: ...

  myFunction:
    type: function
    properties:
      packaging:
        type: stacktape-lambda-buildpack
        properties:
          entryfilePath: path/to/my/lambda.ts
      environment:
        - name: DB_CONNECTION_STRING
          value: $ResourceParam('myDatabase', 'connectionString')

Parameters of Cloudformation resources

To reference parameters of native Cloudformation resources or parameters that are not supported by the $ResourceParam() directive, you can use the $CfResourceParam() directive. It takes two arguments:

  • cloudformation logical name: The logical name of the Cloudformation resource. If you are referencing a resource defined in the cloudformationResources section, use its name. To reference a child resource of a Stacktape resource, you can get a list of child resources using the stacktape stack-info command.
  • parameter name: The parameter of the Cloudformation resource to reference. To see a list of all referenceable Cloudformation parameters for the resources in your stack, see Listing child resources.

Listing child resources

Suppose you want to get a parameter of an AWS::Lambda::Function resource that is a child of the myFunction Stacktape resource.

resources:
  myFunction:
    type: function
    properties:
      packaging:
        type: stacktape-lambda-buildpack
        properties:
          entryfilePath: path/to/my/lambda.ts

You can use the stacktape stack-info --detailed command to get a detailed list of all resources and their children.

stacktape stack-info --detailed --stage my-stage --region eu-west-1

The (truncated) output will look like this, with the logical name of the AWS::Lambda::Function resource highlighted:

resources:
  myFunction:
    resourceType: function
    cloudformationChildResources:
      MyFunctionFunction:
        cloudformationResourceType: AWS::Lambda::Function
        status: DEPLOYED
        referenceableParams:
          - Name
          - Arn
      LogGroup:
        cloudformationResourceType: AWS::Logs::LogGroup
        status: DEPLOYED
        referenceableParams:
          - Name
          - Arn
        logicalName: DeletePostLambdaLogGroup

Now you can use the Lambda function's logical name to get its parameter.

cloudformationResources:
  MySnsTopic:
    type: AWS::SNS::Topic

resources:
  myBucket:
    type: bucket

  processData:
    type: function
    properties:
      packaging:
        type: stacktape-lambda-buildpack
        properties:
          entryfilePath: path/to/my/lambda.ts
      destinations:
        onFailure: $CfResourceParam('MySnsTopic', 'Arn')
      environment:
        - name: BUCKET_NAME
          value: $CfResourceParam('MyBucketBucket', 'Name')