The goal of this quickstart is to examine the AWS S3 component to get you accustomed to developing more advanced components that may have multiple
actions, handle credentials, or handle non-string binary data input fields.
AWS S3 component source code is referenced throughout this quickstart.
You should read Building Your First Custom Component and Writing Custom Components prior to this quickstart to get a sense of project set up, and the
component objects that make up a component project.
input definitions can be written in an
action code block. For example, the Slack component is comprised of a single action, and inputs are defined within that action.
However, for sufficiently complex components, you will likely have multiple actions that rely on the same input. The S3 component, for example, has multiple actions that take the name of an S3 bucket as input. Defining the input field once, and referencing it by multiple actions results in cleaner, more concise code.
Reusable Helper Functions
S3 actions require an AWS S3 client, imported from the AWS SDK. Rather than wrapping the client creation logic into each action, authorization and client creation are placed in a distinct file, auth.ts, and referenced by the actions.
Components can take a variety of credential types - see Authorization Methods for a list of types.
To make AWS S3 API calls, an
secret_access_key key pair are presented to AWS's API.
An API Key / Secret, then, is a reasonable choice to hold AWS credentials.
Acceptable authorization methods are specified in the
credential object is passed into an
perform function as a parameter. For example,
credential object is of type
api_key_secret for this component, the
credential object contains two fields:
Those fields are used in auth.ts to authenticate against the AWS API.
For most components, passing text or JSON as inputs and outputs is sufficient. The Slack component, for example, will only ever post string messages.
The AWS S3 component, on the other hand, might fetch or write non-string data, like images, videos, or PDFs.
Binary Data as Outputs
getObject action reads a file (text or binary data) from an S3 bucket and returns its contents as an action output.
Note that in addition to the file's contents, the return contains
contentType. That might be
image/png, etc., depending on the type of the file.
Binary Data as Inputs
putObject action writes either plain text or a binary file to an S3 bucket. S3 extracts
contentType from the file that is uploaded.
Our input is defined with
type: "data" to indicate that it might contain binary data from a previous step.
If plain text is entered in the
fileContents input field, a string is passed into the
If a reference to binary data is passed in (for example, from an HTTP GET action's output),
fileContents will be an object with
|| syntax to write out
fileContents.data if it exists, or it will fall back to writing out
fileContents as a plaintext string.