Questions tagged [aws-cdk]

The AWS CDK is an infrastructure modeling framework that allows you to define your cloud resources using an imperative programming interface.

Filter by
Sorted by
Tagged with
55 votes
6 answers
30k views

What IAM permissions are needed to use CDK Deploy?

My team has a pipeline which runs under an execution IAM role. We want to deploy code to AWS through CloudFormation or the CDK. In the past, we would upload some artifacts to S3 buckets before ...
Alan Kay's user avatar
  • 685
54 votes
28 answers
62k views

How to resolve: 'Unable to resolve AWS account to use. It must be either configured when you define your CDK or through the environment'

I am trying to run CDK commands to check the diff of my local and remote stack. I am using the following command. cdk diff --profile saml I am getting the following error message Unable to ...
Drew Gallagher's user avatar
45 votes
3 answers
67k views

How to resolve "The maximum number of addresses has been reached" for AWS VPC Elastic IP addresses?

I'm working with CDK/CloudFormation and recently started getting this error when attempting to create a new stack: The maximum number of addresses has been reached. Looking in the AWS Management ...
Steve Chambers's user avatar
41 votes
2 answers
41k views

AWS CDK: How to create an IAM role that can be assumed by multiple principals?

I'm deploying a Lambda function that will be used by CloudFront. The execution role for the function therefore needs to be assumed by edgelambda.amazonaws.com and lambda.amazonaws.com. If I was doing ...
Philip Colmer's user avatar
41 votes
3 answers
62k views

How to import existing VPC in aws cdk?

Hi I am working on aws cdk. I am trying to get existing non-default vpc. I tried below options. vpc = ec2.Vpc.from_lookup(self, id = "VPC", vpc_id='vpcid', vpc_name='vpc-dev') This results in below ...
Niranjan's user avatar
  • 2,129
36 votes
10 answers
43k views

Need to perform AWS calls for account xxx, but no credentials have been configured

I'm trying to deploy my stack to aws using cdk deploy my-stack. When doing it in my terminal window it works perfectly, but when im doing it in my pipeline i get this error: Need to perform AWS calls ...
gospecomid12's user avatar
32 votes
5 answers
50k views

How do I reference cross-stack resources in the same app?

I have an app that has two stacks, both within the same region/account. One of those stacks requires the ARN of a lambda that exists in the other stack. How do I reference this? // within stackA ...
John's user avatar
  • 11.4k
32 votes
1 answer
15k views

Deploy multiple API Gateway stages with AWS CDK

API Gateway has the concept of stages (e.g: dev, test, prod), and deploying multiple stages via the AWS Console is very straightforward. Is it possible to define and deploy multiple stages with AWS ...
Darragh Enright's user avatar
31 votes
5 answers
19k views

AWS CDK VS SDK for IaC

I recently started working with AWS and IaC, I'm using Cloudformation to provision my AWS resources, but I discovered that AWS provide both a SDK and a CDK to enable you to provision resources ...
dev.tom's user avatar
  • 519
30 votes
2 answers
32k views

How can I create a DependsOn relation between EC2 and RDS using aws-cdk

I am currently using the aws-cdk (TypeScript) to create a stack that consists of an EC2 instance and a RDS databaseInstance. The RDS instance needs to be setup before the EC2 instance can be started ...
F. Werkmeister's user avatar
30 votes
6 answers
60k views

Error: Cannot find module 'aws-sdk' in NodeJS AWS Lambda Function

I am trying to access S3 via aws-sdk in my lambda function. import S3 from 'aws-sdk/clients/s3'; const s3 = new S3(); const { Contents: results } = await s3.listObjects({ Bucket: process.env....
daydreamer's user avatar
  • 89.5k
29 votes
10 answers
55k views

How to solve CDK CLI version mismatch

I'm getting following error: This CDK CLI is not compatible with the CDK library used by your application. Please upgrade the CLI to the latest version. (Cloud assembly schema version mismatch: ...
Maciej's user avatar
  • 1,409
28 votes
6 answers
49k views

Specifying a custom role for lambda with the AWS CDK

I realize it's pretty new but I don't see any examples in any language how you would specify a role for the lambda created with the AWS CDK. I was attempting to do this const cdk = require('@...
Ivan Kluzak's user avatar
28 votes
7 answers
38k views

Argument of type 'this' not assignable to parameter 'Construct'

I am trying to call a lambda function into a 'sample app' stack and it is giving me an error because I am trying to pass it a parameter of 'this'. Here is my lambda function export async function ...
aroe's user avatar
  • 509
27 votes
9 answers
32k views

Default credentials can not be used to assume new style deployment roles

Following pipelines readme to set up a deployment pipeline, I ran $ env CDK_NEW_BOOTSTRAP=1 npx cdk bootstrap \ --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess \ ...
heckeop's user avatar
  • 407
27 votes
2 answers
8k views

AWS CDK generated resource identifiers are horrible and not readable. Any way to fix this?

Anyone, that has used AWS CDK suffers from horrible resource identifiers. Examples of Stacks/Nested Stacks names: Or examples of resource names: These identifiers are horrible to read. Is there ...
Laimonas Sutkus's user avatar
26 votes
1 answer
32k views

Write S3 objects with CDK

I am trying to code a CDK doing the job of writing some empty objects inside some folders that I need to be visible in my bucket. I have found this answer https://serverfault.com/questions/957686/...
Nicola Ben's user avatar
26 votes
1 answer
26k views

Purpose and scope of AWS CDK bootstrap stack?

The docs on AWS CDK boostrapping state of the cdk bootstrap command: cdk bootstrap Deploys a CDKToolkit CloudFormation stack into the specified environment(s), that provides an S3 bucket that cdk ...
John's user avatar
  • 11.4k
25 votes
5 answers
27k views

How to add a tag to an AWS-CDK construct

How to add a tag to an AWS-CDK specific construct or even better one tag definition to all ressources created within the stack?
Sma Ma's user avatar
  • 3,539
25 votes
1 answer
18k views

AWS CDK - Vague error while creating an AWS ECS service

I have the following CDK code to create an ECS service. Note: The stack is not fully configured as yet, specifically I don't have the docker image asset or any capacity attached to the cluster. My ...
nija's user avatar
  • 455
25 votes
3 answers
20k views

How to get logical ID of resource with CDK?

I'm attempting to write some tests for a CDK Construct that validates security group rules defined as part of the construct. The Construct looks something like the following. export interface ...
jaredready's user avatar
  • 2,478
25 votes
2 answers
5k views

When to use AWS CloudfrontWebDistribution and when to use AWS Cloudfront Distribution

I see in aws-cdk there are two constructs: CloudFrontWebDistribution Distribution Each have different props that do not look compatible with each other. I'm wondering which one to use?
Stoyan Georgiev's user avatar
24 votes
7 answers
20k views

How to install external modules in a Python Lambda Function created by AWS CDK?

I'm using the Python AWS CDK in Cloud9 and I'm deploying a simple Lambda function that is supposed to send an API request to Atlassian's API when an Object is uploaded to an S3 Bucket (also created by ...
Jamie's user avatar
  • 1,676
24 votes
3 answers
13k views

The difference between a Stack and Construct in AWS CDK

I'm new to CDK and confused about the difference between a Construct and a Stack. With CDK, we can define reusable cloud components known as Construct, and we can further compose these together into a ...
Yunhan Zou's user avatar
23 votes
2 answers
21k views

Unexpected token { ../node_modules/fs-extra/lib/mkdirs/make-dir.js:85 } catch {

I am facing this issue while building my application- 2020-07-12 16:48:39 ....: ^ SyntaxError: Unexpected token { at createScript (vm.js:80:10) at Object.runInThisContext (...
tg_anon's user avatar
  • 231
23 votes
13 answers
48k views

ModuleNotFoundError: No module named aws_cdk

When I run cdk deploy, I get the following error: Traceback (most recent call last): File "app.py", line 3, in <module> from aws_cdk import core ModuleNotFoundError: No module ...
MoneyBall's user avatar
  • 2,413
22 votes
9 answers
10k views

AWS CDK user pool authorizer

I'm trying to create an API gateway using the AWS-CDK and protect the REST endpoints with a Cognito user pool authorizer. I cannot find any examples how one would do this. I thought it should look ...
Ivan Kluzak's user avatar
21 votes
2 answers
20k views

Subscribe a sqs queue to a sns topic that is in a different account, using aws cdk(typescript)

I would like to connect an sqs queue to an sns topic that is in a different account, using cdk (typescript). Below is the code (this code is in a stack) that I think should work but I have some doubts ...
Bashar Mengana's user avatar
19 votes
2 answers
17k views

How to resolve AWS CDK error "Argument of type 'Function' is not assignable to parameter of type 'IFunction'"

I want to get the following example code from https://docs.aws.amazon.com/cdk/latest/guide/serverless_example.html working, but I get a "Argument of type 'Function' is not assignable to parameter ...
Andy Balham's user avatar
18 votes
4 answers
42k views

How to add S3 BucketPolicy with AWS CDK?

I wanna translate this CloudFormation piece into CDK: Type: AWS::S3::BucketPolicy Properties: Bucket: Ref: S3BucketImageUploadBuffer PolicyDocument: Version: "2012-10-17" Statement: ...
Daniel Birowsky Popeski's user avatar
18 votes
4 answers
10k views

aws cdk appsync Schema Creation Status is FAILED with details: Internal Failure while saving the schema

Given the following graphql schema # graphql/schema.graphql type AppUser { userId: String fullName: String } type Query { getUser(userId: String): AppUser getUsers(): [AppUser] } type ...
55 Cancri's user avatar
  • 1,155
18 votes
12 answers
33k views

AWS CDK - How to add an event notification to an existing S3 Bucket

I'm trying to modify this AWS-provided CDK example to instead use an existing bucket. Additional documentation indicates that importing existing resources is supported. So far I am unable to add an ...
cyber-samurai's user avatar
18 votes
6 answers
42k views

AWS CDK -- Cannot find module '@aws-cdk/aws-ec2'

I just started playing around with AWS CDK yesterday and I found something very weird. First of all, I'm using TypeScript for my CDK app (I used cdk init --language typescript to generate the project ...
blue2609's user avatar
  • 881
18 votes
6 answers
11k views

How to install dependencies of lambda functions upon cdk build with AWS CDK

When using AWS SAM I used to run build command which would go through all of my Lambda function packages and install their dependencies (run npm install on them). How can I achieve the same behavior ...
Milan's user avatar
  • 1,840
18 votes
3 answers
11k views

AWS CDK: fixed logical ids

Currently logical ID of a resource is formed by concatenating the names of all of the constructs in the resource’s path and appending an eight-character MD5 hash. This produces garbage like ...
Łukasz's user avatar
  • 2,072
18 votes
1 answer
8k views

How to manage multiple environments using aws cdk?

I am moving our infra code from Terraform to AWS cdk. And I am trying to find an optimal way to manage multiple environments that have multiple stacks to be deployed. If I go by the recommendation in ...
Keshav Potluri's user avatar
18 votes
4 answers
25k views

How do you assign a VPC and security group to a Lambda in AWS CDK?

I have an AWS CDK stack with a lambda function that needs to insert into an RDS database. When the stack is deployed, the lambda function cannot access the database and gives an error: getaddrinfo ...
Robin's user avatar
  • 672
18 votes
4 answers
5k views

AWS CDK passing API Gateway URL to static site in same Stack

I'm trying to deploy an S3 static website and API gateway/lambda in a single stack. The javascript in the S3 static site calls the lambda to populate an HTML list but it needs to know the API Gateway ...
Tim's user avatar
  • 435
17 votes
4 answers
44k views

Add Ingress Rule to Security Groups using AWS CDK

I'm trying to add an ingress rule to a Security Group via the AWS CDK using Python. As per the documentation here - there's a method add_ingress_rule() on the Class aws_cdk.aws_ec2. However - when I ...
SwapnilJak's user avatar
17 votes
1 answer
12k views

Resolution error: Cannot use resource 'x' in a cross-environment fashion, the resource's physical name must be explicit set

I'm trying to pass an ecs cluster from one stack to another stack. I get this error: Error: Resolution error: Resolution error: Resolution error: Cannot use resource 'BackendAPIStack/BackendAPICluster'...
jeznag's user avatar
  • 4,433
17 votes
3 answers
29k views

How to get the account id with cdk

I wrote a simple typescript with AWS CDK and try to get the account id import cdk = require("@aws-cdk/core"); const app = new cdk.Stack(); console.log(app.account); But get below output $ tsc ...
Bill's user avatar
  • 2,778
17 votes
4 answers
26k views

Error: Cannot find module 'index'\nRequire stack:\n- /var/runtime/index.mjs

I'm attempting to deploy a lambda implemented in typescript via CDK. I am able to deploy the lambda successfully, but when I test it, I get the following error: { "errorType": "...
sak's user avatar
  • 3,016
16 votes
4 answers
25k views

enabling CORS for AWS API gateway with the AWS CDK

I'm trying to build an application with the AWS CDK and if I were to build an application by hand using the AWS Console, I normally would enable CORS in API gateway. Even though I can export the ...
Ivan Kluzak's user avatar
16 votes
7 answers
19k views

Lambda can't find modules from outer folders when deployed with CDK

I am deploying some apis to API Gateway using cdk. My problem is the file that contains the lambda(index.ts) can't import any files or npm modules outside that folder(folder named get-users). I tried ...
Lasitha Yapa's user avatar
  • 4,411
15 votes
3 answers
8k views

How to create Cognito IdentityPool with Cognito UserPool as one of the Authentication provider using aws cdk?

I am trying to create a Cognito FederatedIdentityPool with CognitoUserPool as one Authentication Provider. Creating UserPool was easy enough: const userPool = new cognito.CfnUserPool(this, '...
c2tarun's user avatar
  • 786
15 votes
1 answer
59k views

AWS CDK - role and policy creation

How can I translate this CloudFormation to CDK (JavaScript or Java)? I was trying to do it, but this is the first time that I work with CDK and I'm not sure how to do it. ...
juan's user avatar
  • 378
15 votes
1 answer
4k views

How to authorize lambda to perform ses:SendEmail with CDK?

I'm getting runtime exception: AccessDenied: User arn:aws:sts::431535252:assumed-role/...some-lambda' is not authorized to perform 'ses:SendEmail' on resource `arn:aws:ses:us-east-1:52452465462:...
Daniel Birowsky Popeski's user avatar
15 votes
1 answer
12k views

AWS-CDK Unit-Testing and Integration Testing

What is the proper way to unit-test and integration-test my newly built constructs? What should be actually tested? How should it be tested? Thanks!
Romande's user avatar
  • 561
15 votes
1 answer
3k views

determine required permissions for AWS CDK

I'm working with AWS CDK and every time I go to create a new resource (CodePipeline, VPC, etc) I end up in the same loop of... try to deploy "you are not authorized to foo:CreateBar" update IAM ...
Donald P's user avatar
  • 853
14 votes
4 answers
21k views

How to force delete a non empty S3 bucket with versioning enabled?

I have this code block in my CDK file: const artifactBucket = new s3.Bucket(this, "MyBucket", { bucketName: "cdk-cws-pipeline-artifacts", removalPolicy: cdk.RemovalPolicy....
Zulhilmi Zainudin's user avatar

1
2 3 4 5
76