0

Few days back I asked a question to stack overflow community at about custom construct library Question

Although I didn't got the exact answer I was looking for. But somehow I managed to create a custom construct library. But now I have another query on how to host the CDK App as an API.

Below is the snapshot of custom construct library:

test_ec2 = ec2.Instance(self, "APIInstance", 
                                vpc=my_vpc,
                                machine_image=ec2.AmazonLinuxImage(
                                        generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX
                                ),
                                key_name="test-cdk",
                                instance_name=inst-name
                                )

If I want to host above AWS CDK Application as an API that will accept a string for the variable inst-name and will create a EC2 instance. I tried creating it as an lambda function but not sure how to manage "node dependencies and python dependencies" at same time.

Can it be done using an already created EC2 Instance(attaching an IAM Role with permission of cloudformation) and accepting HTTP requests (But don't know how?) Is this making sense?

Thank You in advance to all the devs.

2
  • what do you mean node dependencies and python dependencies? You can use python in Lambda as well Commented Feb 5, 2020 at 9:40
  • Yes I know that. But here the script to be executed is Python script but the console will uses a node to execute it. Commented Feb 6, 2020 at 5:17

1 Answer 1

1

There are many ways to do this. I think the simplest would be to syntesize your cloudformation templates and publish them to S3 ahead of time and use API gateway with a REST API and with AWS request type integration that would create the Cloudformation stack.

Here's a tutorial that explains how to build a REST API with AWS API integration: https://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-aws-proxy.html

Just this is for SNS:ListTopics action, but you would want cloudformation:CreateStack action instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Really appreciated your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.