diff --git a/.gitignore b/.gitignore index 0eac30726..4fc63745e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,16 @@ dist-ssr *.njsproj *.sln *.sw? + +*.swp +package-lock.json +__pycache__ +.pytest_cache +.venv +*.egg-info +.env + +# CDK asset staging directory +.cdk.staging +cdk.out + diff --git a/README.md b/README.md index cf86ff472..7415e5e6f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # React-shop-cloudfront + +### CDK link +[d3q9g2lmtri9eu.cloudfront.net](https://d3q9g2lmtri9eu.cloudfront.net/) + + +Screenshot 2025-02-13 at 09 26 58 + + This is frontend starter project for nodejs-aws mentoring program. It uses the following technologies: - [Vite](https://vitejs.dev/) as a project bundler @@ -36,3 +44,5 @@ Runs tests in console, in browser or with coverage. ### `lint`, `prettier` Runs linting and formatting for all files in `src` folder. + + diff --git a/first-cdk-deployment/.gitignore b/first-cdk-deployment/.gitignore new file mode 100644 index 000000000..37833f8be --- /dev/null +++ b/first-cdk-deployment/.gitignore @@ -0,0 +1,10 @@ +*.swp +package-lock.json +__pycache__ +.pytest_cache +.venv +*.egg-info + +# CDK asset staging directory +.cdk.staging +cdk.out diff --git a/first-cdk-deployment/README.md b/first-cdk-deployment/README.md new file mode 100644 index 000000000..c53f0b50c --- /dev/null +++ b/first-cdk-deployment/README.md @@ -0,0 +1,58 @@ + +# Welcome to your CDK Python project! + +This is a blank project for CDK development with Python. + +The `cdk.json` file tells the CDK Toolkit how to execute your app. + +This project is set up like a standard Python project. The initialization +process also creates a virtualenv within this project, stored under the `.venv` +directory. To create the virtualenv it assumes that there is a `python3` +(or `python` for Windows) executable in your path with access to the `venv` +package. If for any reason the automatic creation of the virtualenv fails, +you can create the virtualenv manually. + +To manually create a virtualenv on MacOS and Linux: + +``` +$ python3 -m venv .venv +``` + +After the init process completes and the virtualenv is created, you can use the following +step to activate your virtualenv. + +``` +$ source .venv/bin/activate +``` + +If you are a Windows platform, you would activate the virtualenv like this: + +``` +% .venv\Scripts\activate.bat +``` + +Once the virtualenv is activated, you can install the required dependencies. + +``` +$ pip install -r requirements.txt +``` + +At this point you can now synthesize the CloudFormation template for this code. + +``` +$ cdk synth +``` + +To add additional dependencies, for example other CDK libraries, just add +them to your `setup.py` file and rerun the `pip install -r requirements.txt` +command. + +## Useful commands + + * `cdk ls` list all stacks in the app + * `cdk synth` emits the synthesized CloudFormation template + * `cdk deploy` deploy this stack to your default AWS account/region + * `cdk diff` compare deployed stack with current state + * `cdk docs` open CDK documentation + +Enjoy! diff --git a/first-cdk-deployment/app.py b/first-cdk-deployment/app.py new file mode 100644 index 000000000..c3348b587 --- /dev/null +++ b/first-cdk-deployment/app.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import os + +import aws_cdk as cdk + +from first_cdk_deployment.first_cdk_deployment_stack import FirstCdkDeploymentStack + + +app = cdk.App() +FirstCdkDeploymentStack(app, "FirstCdkDeploymentStack", + # If you don't specify 'env', this stack will be environment-agnostic. + # Account/Region-dependent features and context lookups will not work, + # but a single synthesized template can be deployed anywhere. + + # Uncomment the next line to specialize this stack for the AWS Account + # and Region that are implied by the current CLI configuration. + + #env=cdk.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION')), + + # Uncomment the next line if you know exactly what Account and Region you + # want to deploy the stack to. */ + + #env=cdk.Environment(account='123456789012', region='us-east-1'), + + # For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html + ) + +app.synth() + + +#!/usr/bin/env python3 diff --git a/first-cdk-deployment/cdk.json b/first-cdk-deployment/cdk.json new file mode 100644 index 000000000..8e95d514b --- /dev/null +++ b/first-cdk-deployment/cdk.json @@ -0,0 +1,85 @@ +{ + "app": "python3 app.py", + "watch": { + "include": [ + "**" + ], + "exclude": [ + "README.md", + "cdk*.json", + "requirements*.txt", + "source.bat", + "**/__init__.py", + "**/__pycache__", + "tests" + ] + }, + "context": { + "@aws-cdk/aws-lambda:recognizeLayerVersion": true, + "@aws-cdk/core:checkSecretUsage": true, + "@aws-cdk/core:target-partitions": [ + "aws", + "aws-cn" + ], + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, + "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, + "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, + "@aws-cdk/aws-iam:minimizePolicies": true, + "@aws-cdk/core:validateSnapshotRemovalPolicy": true, + "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, + "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, + "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, + "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, + "@aws-cdk/core:enablePartitionLiterals": true, + "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, + "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, + "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, + "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, + "@aws-cdk/aws-route53-patters:useCertificate": true, + "@aws-cdk/customresources:installLatestAwsSdkDefault": false, + "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, + "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, + "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, + "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, + "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true, + "@aws-cdk/aws-redshift:columnId": true, + "@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true, + "@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true, + "@aws-cdk/aws-apigateway:requestValidatorUniqueId": true, + "@aws-cdk/aws-kms:aliasNameRef": true, + "@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true, + "@aws-cdk/core:includePrefixInUniqueNameGeneration": true, + "@aws-cdk/aws-efs:denyAnonymousAccess": true, + "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true, + "@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true, + "@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true, + "@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true, + "@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true, + "@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true, + "@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true, + "@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true, + "@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true, + "@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true, + "@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true, + "@aws-cdk/aws-eks:nodegroupNameAttribute": true, + "@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true, + "@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true, + "@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false, + "@aws-cdk/aws-s3:keepNotificationInImportedBucket": false, + "@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature": false, + "@aws-cdk/aws-ecs:disableEcsImdsBlocking": true, + "@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true, + "@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": true, + "@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true, + "@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true, + "@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true, + "@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true, + "@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true, + "@aws-cdk/aws-stepfunctions-tasks:fixRunEcsTaskPolicy": true, + "@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": true, + "@aws-cdk/aws-route53-targets:userPoolDomainNameMethodWithoutCustomResource": true, + "@aws-cdk/aws-elasticloadbalancingV2:albDualstackWithoutPublicIpv4SecurityGroupRulesDefault": true, + "@aws-cdk/aws-iam:oidcRejectUnauthorizedConnections": true, + "@aws-cdk/core:enableAdditionalMetadataCollection": true + } +} diff --git a/first-cdk-deployment/first_cdk_deployment/__init__.py b/first-cdk-deployment/first_cdk_deployment/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/first-cdk-deployment/first_cdk_deployment/first_cdk_deployment_stack.py b/first-cdk-deployment/first_cdk_deployment/first_cdk_deployment_stack.py new file mode 100644 index 000000000..7a43f163c --- /dev/null +++ b/first-cdk-deployment/first_cdk_deployment/first_cdk_deployment_stack.py @@ -0,0 +1,81 @@ +# from aws_cdk import ( +# # Duration, +# Stack, +# # aws_sqs as sqs, +# ) +# from constructs import Construct + +# class FirstCdkDeploymentStack(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 + +# # example resource +# # queue = sqs.Queue( +# # self, "FirstCdkDeploymentQueue", +# # visibility_timeout=Duration.seconds(300), +# # ) + + +from aws_cdk import ( + Stack, + aws_s3 as s3, + aws_cloudfront as cloudfront, + aws_cloudfront_origins as origins, + aws_s3_deployment as s3deploy, + CfnOutput, + RemovalPolicy +) +from constructs import Construct +import os + +class FirstCdkDeploymentStack(Stack): + def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: + super().__init__(scope, construct_id, **kwargs) + + # Create an S3 bucket to store the website files + website_bucket = s3.Bucket( + self, + "ShopReactBucket", + block_public_access=s3.BlockPublicAccess.BLOCK_ALL, + removal_policy=RemovalPolicy.DESTROY, + auto_delete_objects=True + ) + + # Create CloudFront distribution + distribution = cloudfront.Distribution( + self, + "ShopReactDistribution", + default_behavior=cloudfront.BehaviorOptions( + origin=origins.S3Origin(website_bucket), + viewer_protocol_policy=cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + cache_policy=cloudfront.CachePolicy.CACHING_OPTIMIZED, + ), + default_root_object="index.html", + error_responses=[ + cloudfront.ErrorResponse( + http_status=404, + response_http_status=200, + response_page_path="/index.html" + ) + ] + ) + + # Deploy site contents to S3 + s3deploy.BucketDeployment( + self, + "DeployShopReact", + sources=[s3deploy.Source.asset(os.path.join(os.path.dirname(__file__), "..", "..", "dist"))], + destination_bucket=website_bucket, + distribution=distribution, + distribution_paths=["/*"] + ) + + # Output the CloudFront URL + CfnOutput( + self, + "DistributionDomainName", + value=distribution.distribution_domain_name + ) diff --git a/first-cdk-deployment/requirements-dev.txt b/first-cdk-deployment/requirements-dev.txt new file mode 100644 index 000000000..927094516 --- /dev/null +++ b/first-cdk-deployment/requirements-dev.txt @@ -0,0 +1 @@ +pytest==6.2.5 diff --git a/first-cdk-deployment/requirements.txt b/first-cdk-deployment/requirements.txt new file mode 100644 index 000000000..20ba9d5fd --- /dev/null +++ b/first-cdk-deployment/requirements.txt @@ -0,0 +1,2 @@ +aws-cdk-lib==2.178.1 +constructs>=10.0.0,<11.0.0 diff --git a/first-cdk-deployment/source.bat b/first-cdk-deployment/source.bat new file mode 100644 index 000000000..9e1a83442 --- /dev/null +++ b/first-cdk-deployment/source.bat @@ -0,0 +1,13 @@ +@echo off + +rem The sole purpose of this script is to make the command +rem +rem source .venv/bin/activate +rem +rem (which activates a Python virtualenv on Linux or Mac OS X) work on Windows. +rem On Windows, this command just runs this batch file (the argument is ignored). +rem +rem Now we don't need to document a Windows command for activating a virtualenv. + +echo Executing .venv\Scripts\activate.bat for you +.venv\Scripts\activate.bat diff --git a/first-cdk-deployment/tests/__init__.py b/first-cdk-deployment/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/first-cdk-deployment/tests/unit/__init__.py b/first-cdk-deployment/tests/unit/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/first-cdk-deployment/tests/unit/test_first_cdk_deployment_stack.py b/first-cdk-deployment/tests/unit/test_first_cdk_deployment_stack.py new file mode 100644 index 000000000..156c276f9 --- /dev/null +++ b/first-cdk-deployment/tests/unit/test_first_cdk_deployment_stack.py @@ -0,0 +1,15 @@ +import aws_cdk as core +import aws_cdk.assertions as assertions + +from first_cdk_deployment.first_cdk_deployment_stack import FirstCdkDeploymentStack + +# example tests. To run these tests, uncomment this file along with the example +# resource in first_cdk_deployment/first_cdk_deployment_stack.py +def test_sqs_queue_created(): + app = core.App() + stack = FirstCdkDeploymentStack(app, "first-cdk-deployment") + template = assertions.Template.from_stack(stack) + +# template.has_resource_properties("AWS::SQS::Queue", { +# "VisibilityTimeout": 300 +# }) diff --git a/src/components/MainLayout/MainLayout.tsx b/src/components/MainLayout/MainLayout.tsx index ec679471c..05e750695 100755 --- a/src/components/MainLayout/MainLayout.tsx +++ b/src/components/MainLayout/MainLayout.tsx @@ -37,7 +37,7 @@ const MainLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => { color="textSecondary" component="p" > - Thank you for your purchase! + Thank you for your purchase! We Appreciate it