aws-s3-step-function - AWS Solutions Constructs

aws-s3-step-function

All classes are under active development and subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.

Language Package
Python
aws_solutions_constructs.aws_s3_step_function
Typescript
@aws-solutions-constructs/aws-s3-step-function
Java
software.amazon.awsconstructs.services.s3stepfunction

This AWS Solutions Construct implements an Amazon S3 bucket connected to an AWS Step Function.

Note

This construct uses Amazon EventBridge (Amazon CloudWatch Events) to trigger AWS Step Functions. EventBridge is more flexible, but triggering Step Functions with S3 Event Notifications has less latency and is more cost effective. If cost and/or latency is an issue, you should consider deploying aws-s3-lambda and aws-lambda-stepfunctions in place of this construct.

Here is a minimal deployable pattern definition in TypeScript:

import { S3ToStepFunction, S3ToStepFunctionProps } from '@aws-solutions-constructs/aws-s3-step-function'; import * as stepfunctions from '@aws-cdk/aws-stepfunctions'; const startState = new stepfunctions.Pass(stack, 'StartState'); new S3ToStepFunction(this, 'test-s3-step-function-stack', { stateMachineProps: { definition: startState } });

Initializer

new S3ToStepFunction(scope: Construct, id: string, props: S3ToStepFunctionProps);

Parameters

Pattern Construct Props

Name Type Description
existingBucketObj? s3.Bucket An optional, existing bucket to be used instead of the default bucket. If an existing bucket is provided, the bucketProps property will be ignored.
bucketProps? s3.BucketProps Optional user-provided properties to override the default properties for the bucket. Ignored if an existingBucketObj is provided.
stateMachineProps sfn.StateMachineProps Optional user provided props to override the default props for sfn.StateMachine.
eventRuleProps? events.RuleProps Optional user provided eventRuleProps to override the defaults.
deployCloudTrail? boolean Whether to deploy a Trail in AWS CloudTrail to log API events in Amazon S3. Defaults to true.
createCloudWatchAlarms boolean Whether to create recommended CloudWatch alarms.
logGroupProps? logs.LogGroupProps Optional user-provided props to override the default props for the CloudWatch Logs log group.

Pattern Properties

Name Type Description
cloudtrail? cloudtrail.Trail Returns an instance of the Cloudtrail trail created by the pattern.
cloudtrailBucket? s3.Bucket Returns an instance of the bucket created by the pattern for storing Cloudtrail trail data.
cloudtrailLoggingBucket? s3.Bucket Returns an instance of the logging bucket created by the pattern for the primary bucket used by the Cloudtrail trail.
cloudwatchAlarms? cloudwatch.Alarm[] Returns a list of one or more CloudWatch alarms created by the pattern.
s3Bucket? s3.Bucket Returns an instance of the S3 bucket created by the pattern.
s3LoggingBucket? s3.Bucket Returns an instance of the logging bucket created by the pattern for the S3 bucket.
stateMachine sfn.StateMachine Returns an instance of the state machine created by the pattern.
stateMachineLogGroup logs.LogGroup Returns an instance of the log group created by the pattern for the state machine.

Default settings

Out-of-the-box implementation of this pattern without any overrides will set the following defaults:

Amazon S3 Bucket

  • Configure Access logging for S3 Bucket.

  • Enable server-side encryption for S3 Bucket using AWS managed KMS Key.

  • Turn on the versioning for S3 Bucket.

  • Don't allow public access for S3 Bucket.

  • Retain the S3 Bucket when deleting the CloudFormation stack.

  • Enforce encryption of data in transit.

  • Applies lifecycle rule to move noncurrent object versions to Glacier storage after 90 days.

AWS CloudTrail

  • Configure a Trail in AWS CloudTrail to log API events in Amazon S3 related to the Bucket created by the Construct.

Amazon CloudWatch Events Rule

  • Grant least privilege permissions to CloudWatch Events to trigger the Lambda Function.

AWS Step Function

  • Enable CloudWatch logging for API Gateway.

  • Deploy best practices CloudWatch Alarms for the Step Function.

Architecture

GitHub

To view the code for this pattern, create/view issues and pull requests, and more:
@aws-solutions-constructs/aws-s3-step-function