Skip to content

benbpyle/sqs-redrive-sample

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Setting up the Sample

I wish there was more to it in a way but there isn't. It all feels super simple. And once the SDK Integration is put into Step Functions, this will go from building an SQS re-drive with Golang and Step Functions to building an SQS re-drive just Step Functions.

Running the Infrastructure Code

cdk deploy # will deploy all the code

Resources created

  • Lambdas
    • Redriver
    • Redrive status check
    • Processor
  • SQS
    • Sample Queue
    • Dead Letter Queue
  • Step Functions
    • Workflow State Machine
  • CloudWatch
    • Lambda log groups
    • State Machine log group

Processor Lambda

There is a Processor Lambda in this code as well. It reads from the primary SQS to let you simulate failure and success. In the processor CDK code, there is an environment variable that indicates how the processor should work. It's the FAIL variable. true means the Lambda will be put in Failure Mode

this._func = new GoFunction(scope, `ProcessorFunc`, {
    entry: "src/processor",
    functionName: "processor",
    timeout: Duration.seconds(30),
    environment: {
        IS_LOCAL: "false",
        LOG_LEVEL: "debug",
        FAIL: "true",
    },
});
func handler(ctx context.Context, event events.SQSEvent) error {
	log.WithFields(log.Fields{
		"message": event,
	}).Info("Handling Processing")

	fail, _ := strconv.ParseBool(os.Getenv("FAIL"))

	if fail {
		return errors.New("in failure mode")
	}

	return nil
}

Putting a Message on the Queue

aws sqs send-message --queue-url https://sqs.<region>.amazonaws.com/<account-id>/sample --message-body "Hello World"

Starting the State Machine

aws stepfunctions start-execution --state-machine-arn arn:aws:states:<region>:<account>:stateMachine:SqsRedriveWorkflow --input "{\"queueArn\": \"arn:aws:sqs:<region>:<account>:sample-dlq\"}"

Tearing Down

cdk destroy

About

Sample Project to highlight SQS Re-drive capabilities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published