Hi AWS, I am writing infrastructure code using AWS CDK (Python) and I have written code to deploy multiple stacks, for e.g. one stack is deploying SQS queue and the other stack is deploying multiple AWS Lambda functions. Here are the code files:
crud_stack.py
from aws_cdk import (
Stack,
aws_lambda as aws_lambda,
)
from constructs import Construct
from aws_cdk.aws_lambda import Function, Code
from aws_cdk_web.crud import crud_root
class AwsCdkCrudStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# The code that defines your stack goes here
# defining a lambda function
Function(
scope=self,
id="CreateFunction",
code=Code.from_asset(f'{crud_root}/create'),
runtime=aws_lambda.Runtime.PYTHON_3_9,
handler='index.handler',
function_name="CreateFunction"
)
Function(
scope=self,
id="ReadFunction",
code=Code.from_asset(f'{crud_root}/read'),
runtime=aws_lambda.Runtime.PYTHON_3_9,
handler='index.handler',
function_name="ReadFunction"
)
Function(
scope=self,
id="UpdateFunction",
code=Code.from_asset(f'{crud_root}/update'),
runtime=aws_lambda.Runtime.PYTHON_3_9,
handler='index.handler',
function_name="UpdateFunction"
)
Function(
scope=self,
id="DeleteFunction",
code=Code.from_asset(f'{crud_root}/delete'),
runtime=aws_lambda.Runtime.PYTHON_3_9,
handler='index.handler',
function_name="DeleteFunction"
)
aws_cdk_web_stack.py
from aws_cdk import (
Duration,
Stack,
aws_sqs as sqs,
)
from constructs import Construct
from aws_cdk_web.crud_stack import AwsCdkCrudStack
class AwsCdkWebStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# The code that defines your stack goes here
AwsCdkCrudStack(
scope=self,
construct_id='CrudStack',
stack_name='CrudStack'
)
Now as you know app.py is the entrypoint for your CDK application and here is the code for the same where I am overriding the default values provided by CDK, for e.g. the default S3 bucket which is used to store assets and artifacts. Here is the code file for app.py:
#!/usr/bin/env python3
import os
import aws_cdk as cdk
from aws_cdk import DefaultStackSynthesizer
from aws_cdk_web.aws_cdk_web_stack import AwsCdkWebStack
from aws_cdk_web.crud_stack import AwsCdkCrudStack
app = cdk.App()
AwsCdkWebStack(
app,
"AwsCdkWebStack",
synthesizer=DefaultStackSynthesizer(file_assets_bucket_name="aws-cdk-bootcamp-bucket"
))
AwsCdkCrudStack(
app,
"CrudStack",
synthesizer=DefaultStackSynthesizer(file_assets_bucket_name="aws-cdk-bootcamp-bucket"
))
app.synth()
As you can see in the code I have used a customized bucket name i.e. "aws-cdk-bootcamp-bucket". Now when I ran the CDK CLI commands:
cdk bootstrap aws://123456789012/us-east-1
⏳ Bootstrapping environment aws://123456789012/us-east-1...
Trusted accounts for deployment: (none)
Trusted accounts for lookup: (none)
Using default execution policy of 'arn:aws:iam::aws:policy/AdministratorAccess'. Pass '--cloudformation-execution-policies' to customize.
✅ Environment aws://123456789012/us-east-1 bootstrapped (no changes).
cdk deploy --all
✨ Synthesis time: 12.85s
AwsCdkWebStack
CrudStack: start: Building 8d9e130ff7bc558e2cf4cb3d84c4bbae46c5da0230057c1c0e55ffa1e3810c49:current_account-current_region
CrudStack: success: Built 8d9e130ff7bc558e2cf4cb3d84c4bbae46c5da0230057c1c0e55ffa1e3810c49:current_account-current_region
CrudStack: start: Publishing 8d9e130ff7bc558e2cf4cb3d84c4bbae46c5da0230057c1c0e55ffa1e3810c49:current_account-current_region
CrudStack: start: Building ab7212e1a14060165da30b84dafe9b7f2edd3dc9eddd8b12f734fab97b00c969:current_account-current_region
CrudStack: success: Built ab7212e1a14060165da30b84dafe9b7f2edd3dc9eddd8b12f734fab97b00c969:current_account-current_region
CrudStack: start: Publishing ab7212e1a14060165da30b84dafe9b7f2edd3dc9eddd8b12f734fab97b00c969:current_account-current_region
CrudStack: start: Building d65316cbff0468c89820b390ed22ea0068c422c95863cc612607d89b2c345fdc:current_account-current_region
CrudStack: success: Built d65316cbff0468c89820b390ed22ea0068c422c95863cc612607d89b2c345fdc:current_account-current_region
CrudStack: start: Publishing d65316cbff0468c89820b390ed22ea0068c422c95863cc612607d89b2c345fdc:current_account-current_region
CrudStack: start: Building 69a6bef0f8daddd47dda0065e937611ff2bac5f0fed73aadfe3fa7f9a7abe258:current_account-current_region
CrudStack: success: Built 69a6bef0f8daddd47dda0065e937611ff2bac5f0fed73aadfe3fa7f9a7abe258:current_account-current_region
CrudStack: start: Building f6b313259f2d3b9779c7fad65733ba8e32060cc3bb1160b393c8cd9128246bfc:current_account-current_region
CrudStack: success: Built f6b313259f2d3b9779c7fad65733ba8e32060cc3bb1160b393c8cd9128246bfc:current_account-current_region
CrudStack: start: Publishing 69a6bef0f8daddd47dda0065e937611ff2bac5f0fed73aadfe3fa7f9a7abe258:current_account-current_region
CrudStack: start: Publishing f6b313259f2d3b9779c7fad65733ba8e32060cc3bb1160b393c8cd9128246bfc:current_account-current_region
AwsCdkWebStack: deploying... [2/3]
CrudStack: fail: No bucket named 'cdk-hnb659fds-assets-123456789012-us-east-1'. Is account 123456789012 bootstrapped?
CrudStack: fail: No bucket named 'cdk-hnb659fds-assets-123456789012-us-east-1'. Is account 123456789012 bootstrapped?
CrudStack: fail: No bucket named 'cdk-hnb659fds-assets-123456789012-us-east-1'. Is account 123456789012 bootstrapped?
CrudStack: fail: No bucket named 'cdk-hnb659fds-assets-123456789012-us-east-1'. Is account 123456789012 bootstrapped?
CrudStack: fail: No bucket named 'cdk-hnb659fds-assets-123456789012-us-east-1'. Is account 123456789012 bootstrapped?
✅ AwsCdkWebStack (no changes)
✨ Deployment time: 3.5s
Stack ARN:
arn:aws:cloudformation:us-east-1:123456789012:stack/AwsCdkWebStack/4ac2c5b0-2598-11ef-beef-0e84039c393b
✨ Total time: 16.35s
❌ Deployment failed: Error: Failed to publish asset d65316cbff0468c89820b390ed22ea0068c422c95863cc612607d89b2c345fdc:current_account-current_region
at Deployments.publishSingleAsset (C:\Users\amang\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:445:11645)
at async Object.publishAsset (C:\Users\amang\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:445:197443)
at async C:\Users\amang\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:445:181344
Failed to publish asset d65316cbff0468c89820b390ed22ea0068c422c95863cc612607d89b2c345fdc:current_account-current_region
AFAIK the code seems fine to me but I don't know what is going wrong which is giving me this error. Please advise.