Stacktape

Sign up



Referencing parameters

Introduction

  • When using a cloud architecture composed of multiple infrastructure resources, these resources usually need to communicate with each other.
  • To do that, they usually need some kind of indentifier or address - for example a database endpoint, API Gateway URL or an ARN (Amazon Resource Name). These identifiers are assigned dynamically, and they can't be known ahead of time (before the stack is deployed).
  • Stacktape allows you to easily create dynamic references to these resources using $ResourceParam() and $CfResourceParam() directives.

Parameters of Stacktape resources

Copy

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

Example usage of $ResourceParam() directive.

Parameters of Cloudformation resources

  • To reference parameters of native Cloudformation resources or parameters that aren't supported by $ResourceParam() directive, you can use the $CfResourceParam() directive.
  • Arguments:
    • 1. cloudformation logical name - name of the AWS Cloudformation resource.
      • If you want to reference a resource defined in cloudformationResources section, just use its name.
      • If you want to reference a child resources of a Stacktape resource, you can get a list of child resource using the stack-info command
    • 2. parameter name - parameter of the AWS Cloudformation resource to reference. To see a list of all referenceable cloudformation parameters for resources in your stack, refer to Listing child resources.

Listing child resources

Let's say we want to get parameter of the AWS Lambda resource (cloudformation type AWS::Lambda::Function) that is a child resource of myFunction stacktape resource.

Copy

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


We can use stack-info command to get a detailed list of all resources and their child resources.

Copy

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

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

Copy

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


Now we can use the lambda function's logical name to get its parameter.

Copy

cloudformationResources:
MySnsTopic:
type: AWS::SNS::Topic
resources:
myBucket:
type: bucket
processData:
type: function
properties:
packageConfig:
filePath: path/to/my/lambda.ts
destinations:
onFailure: $CfResourceParam('MySnsTopic', 'Arn')
environment:
name: BUCKET_NAME
value: $CfResourceParam('MyBucketBucket', 'Name')
Need help? Ask a question on SlackDiscord or info@stacktape.com.