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.
3,751
questions
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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....
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: ...
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('@...
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 ...
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 \
...
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 ...
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/...
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 ...
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?
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 ...
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 ...
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?
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 ...
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 ...
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 (...
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 ...
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 ...
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 ...
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 ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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'...
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 ...
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": "...
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 ...
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 ...
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, '...
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.
...
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:...
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!
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 ...
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....