projenstatemachineexample

package module
v2.0.521 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

projen-simple

License Release npm downloads pypi downloads NuGet downloads repo languages

npm (JS/TS) PyPI (Python) Maven (Java) Go NuGet
Link Link Link Link Link

Build a custom construct based on an example in an AWS Blog post and use projen to publish to 5 language repositories, i.e., npm, PyPI, Central Maven, NuGet, and Go.

Architecture

This library constrcution is referred to the first example in this AWS blog, Introducing Amazon API Gateway service integration for AWS Step Functions written by Benjanmin Smith. After you deploy the stack with whatever programming language you like, i.e., Typescript, Python, Java, or C sharp, you'll get a view similar to the following diagram: image

How to utilize polyglot packages and deploy

TypeScript

$ cdk --init language typescript
$ yarn add projen-statemachine-example
import { StateMachineApiGatewayExample } from 'projen-statemachine-example';

 export class TypescriptStack extends cdk.Stack {
 constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
     super(scope, id, props);

     const stageName = 'default';
     const partPath = 'pets';
     const exampleConstruct = new StateMachineApiGatewayExample(this, 'KerKer', {
         stageName: stageName, partPath: partPath});

     new cdk.CfnOutput(this, 'OStateMachine', {
         value: exampleConstruct.stateMachine.stateMachineArn});
     new cdk.CfnOutput(this, 'OExecutionOutput', {
         value: exampleConstruct.executionInput, description: 'Sample input to StartExecution.'});
 }

Python

$ cdk init --language python
$ cat <<EOL > requirements.txt
aws-cdk.core
scotthsieh_projen_statemachine
EOL
$ python -m pip install -r requirements.txt
from aws_cdk import core as cdk
from scotthsieh_projen_statemachine import StateMachineApiGatewayExample

class PythonStack(cdk.Stack):
    def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
         super().__init__(scope, construct_id, **kwargs)

         stage_name = 'default'
         part_path = 'pets'
         example_construct = StateMachineApiGatewayExample(
             self, 'PythonStatemachne', stage_name=stage_name, part_path=part_path,
         )

         cdk.CfnOutput(self, "OStateMachine",
             value=example_construct.state_machine.state_machine_arn
         )
         cdk.CfnOutput(self, "OExecutionOutput", value=example_construct.execution_input, description="Sample input to StartExecution.")

Java

$ cdk init --language java
$ mvn package
.
.
<properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <custom.construct.version>2.0.474</custom.construct.version>
     <cdk.version>2.149.0</cdk.version>
     <junit.version>5.7.1</junit.version>
 </properties>
 .
 .
 <dependencies>
     <!-- AWS Cloud Development Kit -->
     .
     .
     .
     <dependency>
         <groupId>io.github.hsiehshujeng</groupId>
         <artifactId>projen-statemachine</artifactId>
         <version>${custom.construct.version}</version>
     </dependency>
     .
     .
     .
 </dependencies>
package com.myorg;

import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.CfnOutput;
import software.amazon.awscdk.core.CfnOutputProps;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.core.StackProps;
import io.github.hsiehshujeng.projen.statemachine.*;

public class JavaStack extends Stack {
    public JavaStack(final Construct scope, final String id) {
        this(scope, id, null);
     }

     public JavaStack(final Construct scope, final String id, final StackProps props) {
         super(scope, id, props);

         String stageName = "default";
         String partPath = "pets";
         StateMachineApiGatewayExample exampleConstruct = new StateMachineApiGatewayExample(this, "KerKer",
             StateMachineApiGatewayExampleProps.builder()
                 .stageName(stageName)
                 .partPath(partPath)
                 .build());

         new CfnOutput(this, "OStateMachine",
             CfnOutputProps.builder()
                 .value(exampleConstruct.getStateMachine().getStateMachineArn())
                 .build());
         new CfnOutput(this, "OExecutionOutput", CfnOutputProps.builder()
             .value(exampleConstruct.getExecutionInput())
             .description("Sample input to StartExecution.")
             .build());
     }
 }

C#

$ cdk init --language csharp
$ dotnet add src/Csharp package Projen.Statemachine --version 2.0.474
using Amazon.CDK;
using ScottHsieh.Examples;

namespace Csharp
{
    public class CsharpStack : Stack
    {
        internal CsharpStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            string stageName = "default";
            string partPath = "pets";

            var exampleConstruct = new StateMachineApiGatewayExample(this, "KerKer", new StateMachineApiGatewayExampleProps
            {
                StageName = stageName,
                PartPath = partPath
            });

            new CfnOutput(this, "OStateMachine", new CfnOutputProps
            {
                Value = exampleConstruct.StateMachine.StateMachineArn
            });
            new CfnOutput(this, "OExecutionOutput", new CfnOutputProps
            {
                Value = exampleConstruct.ExecutionInput,
                Description = "Sample input to StartExecution."
            });
        }
    }
 }

References

Documentation

Overview

An example construct for deploying to npm, PyPi, Maven, and Nuget with Amazon API Gateway and AWS Step Functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStateMachineApiGatewayExample_Override

func NewStateMachineApiGatewayExample_Override(s StateMachineApiGatewayExample, parent constructs.Construct, name *string, props *StateMachineApiGatewayExampleProps)

func StateMachineApiGatewayExample_IsConstruct

func StateMachineApiGatewayExample_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`.

Types

type StateMachineApiGatewayExample

type StateMachineApiGatewayExample interface {
	constructs.Construct
	// sample input to start execution for the workflow.
	ExecutionInput() *string
	// The tree node.
	Node() constructs.Node
	// the representation of a state machine.
	StateMachine() awsstepfunctions.StateMachine
	// Returns a string representation of this construct.
	ToString() *string
}

Converted from an AWS Blog post.

It is the first example mentioned in https://aws.amazon.com/tw/blogs/compute/introducing-amazon-api-gateway-service-integration-for-aws-step-functions/. This constcut will create an API Gateway Rest API with two methods and are manipulated by a state machine managed in AWS StepFucntions.

func NewStateMachineApiGatewayExample

func NewStateMachineApiGatewayExample(parent constructs.Construct, name *string, props *StateMachineApiGatewayExampleProps) StateMachineApiGatewayExample

type StateMachineApiGatewayExampleProps

type StateMachineApiGatewayExampleProps struct {
	// The path part for the resource.
	// Default: 'pets'.
	//
	PartPath *string `field:"required" json:"partPath" yaml:"partPath"`
	// A stage name for the rest api.
	// Default: 'default'.
	//
	StageName *string `field:"required" json:"stageName" yaml:"stageName"`
}

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL