import * as cdk from "aws-cdk-lib";
import * as lambda from 'aws-cdk-lib/aws-lambda'
import * as sfn from 'aws-cdk-lib/aws-stepfunctions'
export default class CdkStack extends cdk.Stack {
constructor(scope?: Construct, id?: string, props: StackProps) {
super(scope, id, props);
// Get the CloudFormation Output value that is already existing in AWS Server with 'Export name' in Output values
const token = cdk.Fn.importValue(['Export Name' in an already existing Cloud Formation Stack])
// Get the Exising Lambda Function
const createMediaLambda = lambda.Function.fromFunctionArn(
this,
'[Sample String value for debugging]',
'[lambda ARN]' //cloud formation import!
);
// Create the json that AWS can understand and transform
const createMediaJson = {
Type: 'Task',
Resource: token,
Parameters: {
contentId: '$.contentId'
},
Next: 'UpdateStatusWaiting'
}
// Make a custom State
const createMedia = new sfn.CustomState(this, "CreateMedia", {
stateJson: createMediaJson
});
// Make a chain for the Step Functions
const chain = sfn.Chain.start(createMedia).next(updateStatusWaiting);
// Create a StateMachine (for Step Functions)
const stateMachine = new sfn.StateMachine(this, "stateMachine", {
definition: chain,
timeout: Duration.seconds(100),
})
// Grant Invoking Access for the State Machine to run the Lambda function.
createMediaLambda.grantInvoke(stateMachine)
}
}
'AWS > CDK' 카테고리의 다른 글
AWS CloudFormation Versioning (0) | 2022.06.29 |
---|---|
[Fixed] CDK parameter doesn't read from parameter using ASL (0) | 2022.06.18 |
[AWS CDK] Testing Constructs (0) | 2022.04.07 |
[AWS CDK] Clean up CDK Stack (0) | 2022.04.06 |
[AWS CDK] CDK Diff and CDK Deploy (0) | 2022.04.06 |