banner

KuchBhiLearning - A free website to learn and code

This is a good learning site. This contains details of cloud computing, AWS, AWS-CDK, AWS-SDK codes and examples including S3, Redis, lambda, api-gateway, cloudfront, cloudformation.

 Add VPC to Lambda CDK

CDK provides lot of methods which can be used create new resources and then use that reference for creating/updating another resource.

But there are wide use cases where some of the resources are already created and we just need to import it for another resource.

One such example is VPC, we do not need to create multiple VPC's. Having a single VPC can also does the job pretty well. In this case we do not want to create VPC through CDK.

If you want to check how to import VPC, then click here (https://kuchbhilearning.blogspot.com/2022/10/httpskuchbhilearning.blogspot.comimport-existing-vpc-in-aws-cdk.html)

Now let's jump to assigning VPC to lambda.

  const hello = new lambdaNode.NodejsFunction(stack, `lambda-hello`, {
    entry: path.join(__dirname, 'src/hello.ts'), // Path to handler
    timeout: Duration.seconds(30),
    vpc,
    handler: 'handler', // file is "hello"; function is "handler"
    environment: {
      FUNCTION_NAME: 'hello',
    },
  });

We are using NodejsFunction for creating the lambda, which allows us to pass the VPC.

Further Reading

Custom Header in Cloudfront(https://kuchbhilearning.blogspot.com/2022/11/add-custom-header-in-cloudfrontpass.html)

API Gateway and CloudFront in the same domain with different path(https://kuchbhilearning.blogspot.com/2022/10/api-gateway-and-cloud-front-in-same.html)

Pass query params from CloudFront to API Gateway AWS-CDK(https://kuchbhilearning.blogspot.com/2022/10/pass-query-params-from-cloudfront-to.html)

Add CloudFront Behavior and Origin using AWS-CDK(https://kuchbhilearning.blogspot.com/2022/10/add-cloudfront-behavior-and-origin.html)

AWS CloudFront Function(https://kuchbhilearning.blogspot.com/2022/09/aws-cloudfront-function-aws-has.html)


No comments:

Post a Comment

If you have any doubts, Please let me know

Copyright 2022, KuchBhiLearning - A free website to learn and code. All rights Reserved.
| Designed by Yaseen Shariff