CDK deploy not recognizing my bootstrap and SSM parameter - aws-cdk

I have a project with CDK and CDK Deploy does not work. My project is a simple CDK app that has been started with cdk init app --language typescript and was working at first. I don't have anything but a lambda and an api gateway in this project.
After adding NodejsFunction from #aws-cdk/aws-lambda-nodejs I faced some errors but by installing docker locally and some changes all those were resolved and synth completes successfully now.
I run cdk bootstrap and then cdk synth and then cdk deploy with the last one here is the error I see: (the rest finishes successfully)
SSM parameter /cdk-bootstrap/pipeline/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)
bootstrap and synth work fine, my aws configure has been done and no errors anywhere but the deploy doesn't work.
More details:
Error:
MyStackNameStack failed: Error: MyStackNameStack: SSM parameter /cdk-bootstrap/pipeline/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)
at CloudFormationDeployments.validateBootstrapStackVersion (/usr/local/lib/node_modules/aws-cdk/lib/api/cloudformation-deployments.ts:297:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at CloudFormationDeployments.publishStackAssets (/usr/local/lib/node_modules/aws-cdk/lib/api/cloudformation-deployments.ts:272:7)
at CloudFormationDeployments.deployStack (/usr/local/lib/node_modules/aws-cdk/lib/api/cloudformation-deployments.ts:179:5)
at CdkToolkit.deploy (/usr/local/lib/node_modules/aws-cdk/lib/cdk-toolkit.ts:184:24)
at initCommandLine (/usr/local/lib/node_modules/aws-cdk/bin/cdk.ts:213:9)
MyStackNameStack: SSM parameter /cdk-bootstrap/pipeline/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Package.json and CLI versions:
CDK version: 1.116.0
"#aws-cdk/aws-apigateway": "^1.116.0",
"#aws-cdk/aws-lambda": "^1.116.0",
"#aws-cdk/aws-lambda-nodejs": "^1.116.0",
"#aws-cdk/core": "^1.116.0",

I only use this:
cdk bootstrap

Related

Error when deploying Lambda Docker using AWS CDK

I'm following https://sbstjn.com/blog/aws-cdk-lambda-docker-container-example/ and deploying Lambda Docker using AWS CDK. On 'cdk deploy' I get the following error. Link to my github repo is https://github.com/aqilzeeshan/cdk_dockerlambda
Can anyone tell me please what is the problem ? Thanks
Do you wish to deploy these changes (y/n)? y
CdkLambdaDockerStack: deploying...
[0%] start: Publishing dcfb2f152c6c0b2ca779c90dee5d59d3b510805a3ed884b310200624e32a4b27:current
Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:156:25)
at writeGeneric (internal/stream_base_commons.js:147:3)
at Socket._writeGeneric (net.js:785:11)
at Socket._write (net.js:797:8)
at writeOrBuffer (internal/streams/writable.js:358:12)
at Socket.Writable.write (internal/streams/writable.js:303:10)
at C:\Users\amuham210\AppData\Roaming\npm\node_modules\aws-cdk\node_modules\cdk-assets\lib\private\shell.ts:28:19
at new Promise (<anonymous>)
at Object.shell (C:\Users\amuham210\AppData\Roaming\npm\node_modules\aws-cdk\node_modules\cdk-assets\lib\private\shell.ts:26:10)
at Docker.execute (C:\Users\amuham210\AppData\Roaming\npm\node_modules\aws-cdk\node_modules\cdk-assets\lib\private\docker.ts:75:13)
I found the problem. Docker needs to be installed to build the image. After installing docker on machine where I run 'cdk deploy' above issue is resolved.

Why is an admin account getting permission denied when updating a BucketPolicy?

I have an AWS CDK script that I'm now unable to deploy. I could deploy it before adding a bucket policy. After adding a bucket policy, it fails to deploy. Here's the Python code:
bucket = aws_s3.Bucket(
self,
"myBucket",
bucket_name="mybucket",
access_control=aws_s3.BucketAccessControl.PRIVATE,
versioned=True,
encryption=aws_s3.BucketEncryption.S3_MANAGED,
block_public_access=aws_s3.BlockPublicAccess.BLOCK_ALL
)
policy_statement = aws_iam.PolicyStatement(
effect=aws_iam.Effect.DENY,
actions=["*"],
resources=[bucket.arn_for_objects("*")],
conditions={ "Bool": { "aws:SecureTransport": "false" } }
)
policy_statement.add_any_principal()
bucket.add_to_resource_policy(policy_statement)
I deploy this stack using this command: cdk deploy --require-approval=never
And I see the following error:
2/4 | 10:01:03 AM | CREATE_IN_PROGRESS | AWS::S3::BucketPolicy | myBucket/Policy (myBucketPolicyAFBF75F8)
3/4 | 10:01:04 AM | CREATE_FAILED | AWS::S3::BucketPolicy | myBucket/Policy (myBucketPolicyAFBF75F8) API: s3:PutBucketPolicy Access Denied
The user I'm using to deploy this is an admin user with access to everything. I've confirmed that I can log into the console, create this bucket, and add this Bucket Policy with this same user, but for some reason I get a permission denied error when deploying the CDK script.
I'm relatively new to CDK and AWS, so, it may be something simple that I'm missing. Any help would be appreciated.
AWS CLI Version 2.0.3
Python Version 3.7.5
CDK Version 1.31.0 (build 8f3ac79)
Botocore Version 2.0.0dev7
Windows 10
UPDATE:
I updated my CDK install to the latest and now it's deploying just fine. No code changed, just my CDK version. I'm now running 1.32.2 (build e19e206) and it deployed. In looking through the release notes, I can't tell exactly why it was broken before and why it's working now, but they did make some changes in IAM and one of them must have fixed this.

Trying to install logging on google cloud run but it's failing

I am trying to follow these instructions to log correctly from java to logback to cloudrun...
https://cloud.google.com/logging/docs/setup/java
If I used jdk8, I get alpn missing jetty issues so I moved to a Docker image openjdk:10-jre-slim
and my DockerFile is simple
FROM openjdk:10-jre-slim
RUN mkdir -p ./webpieces
COPY . ./webpieces/
COPY config/logback.cloudrun.xml ./webpieces/config/logback.xml
WORKDIR "/webpieces"
ENTRYPOINT ./bin/customerportal -http.port=:$PORT -hibernate.persistenceunit=cloud-production
AND the only difference is I switched the image from openjdk:8-jdk-alpine which worked fine!!!
When I deploy to google cloud I get this error...
Deploying container to Cloud Run service [staging-customerportal] in project [orderly-gcp] region [us-west1]
⠏ Deploying... Cloud Run error: Invalid argument error. Invalid ENTRYPOINT. [name: "gcr.io/orderly-gcp/customerportal2#sha256:6c1c2e7531684d8f50a3120f1de60cade841ab1d9069b
704ee3fd8499c5b7779"
error: "Invalid command \"/bin/sh\": file not found"
].
X Deploying... Cloud Run error: Invalid argument error. Invalid ENTRYPOINT. [name: "gcr.io/orderly-gcp/customerportal2#sha256:6c1c2e7531684d8f50a3120f1de60cade841ab1d9069b
704ee3fd8499c5b7779"
error: "Invalid command \"/bin/sh\": file not found"
].
. Routing traffic...
Deployment failed
ERROR: (gcloud.run.deploy) Cloud Run error: Invalid argument error. Invalid ENTRYPOINT. [name: "gcr.io/orderly-gcp/customerportal2#sha256:6c1c2e7531684d8f50a3120f1de60cade841ab1d9069b704ee3fd8499c5b7779"
error: "Invalid command \"/bin/sh\": file not found"
].
However, when I run locally to test, I get this error on project ID being required so it seems it is working. SIDE QUESTION: How to simulate this project ID so I can still run locally?
03:10:08,650 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CLOUD]
03:10:09,868 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter#14:13 - RuntimeException in Action for tag [appender] java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the builder.
at java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the builder.
at at com.google.common.base.Preconditions.checkArgument(Preconditions.java:142)
at at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:285)
at at com.google.cloud.logging.LoggingOptions.<init>(LoggingOptions.java:98)
at at com.google.cloud.logging.LoggingOptions$Builder.build(LoggingOptions.java:92)
at at com.google.cloud.logging.LoggingOptions.getDefaultInstance(LoggingOptions.java:52)
at at com.google.cloud.logging.logback.LoggingAppender.getLoggingOptions(LoggingAppender.java:246)
at at com.google.cloud.logging.logback.LoggingAppender.getProjectId(LoggingAppender.java:209)
at at com.google.cloud.logging.logback.LoggingAppender.start(LoggingAppender.java:194)
at at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
at at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
at at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
at at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
at at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
The Java 10 version is EOL, and the official images has been removed. More detail here
Prefer a Java 11 version.
Anyway, when you use version, some are optimized and does not install bash by default (for reducing their size) and you have to install it by yourselves.
For a local run, I don't recommend to use a JSON key file (in general, don't use JSON key file, except for automated system out of GCP) due to security constraint, key rotation, secure storage,...
For setting the project, simply perform this command gcloud config set project MY_PROJECT. You don't need credential for this.
Since your current question is how to simulate the project ID for local testing:
You should download service account key file from https://console.cloud.google.com/iam-admin/serviceaccounts/project?project=MY_PROJECT, make it accessible inside docker container and activate it via
gcloud auth activate-service-account --key-file my_service_account.json
gcloud config set project MY_PROJECT
This problem may be due to the fact that alpine doesn't have bash:
"/bin/sh" therefore a solution could be to remove the dependency on bash itself by not using bash or by using exec instead of bash.
in my case I solved the problem by using a more complete base image, instead of alpine for instance.
HTH

cdk LS failed because it doesn't find the app

I'm running the sample-app but seems it doesn't work anymore
.env) [cdk-workshop]gdm$ cdk ls
CDK CLI >= 1.10.0 is required to interact with this app
(.env) [cdk-workshop]gdm$
Why?
the code is exactly https://cdkworkshop.com/30-python/20-create-project/100-cdk-init.html
the problem was my ckd version(1.9.0)
I've updated and now it works

Build a Docker image of an app using Gradle

I have made an application using JHipster, of which I want to create a Docker image using Gradle. I was following this guide but when I run the command ./gradlew bootWar -Pprod buildDocker, it gives an error:
Task 'bootWar' not found in root project 'seodin'. Some candidates
are: 'bootRun'.
I also tried running the command with 'bootRun', but I get the following error in this case:
Execution failed for task ':bootRun'.
Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1
I am stuck at this point and any help is appreciated. [Note: Java and all other dependencies are installed and the JHipster app is working fine on localhost]

Resources