Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task4 #126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Task4 #126

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cdk_java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.classpath.txt
target
.classpath
.project
.idea
.settings
.vscode
*.iml

# CDK asset staging directory
.cdk.staging
cdk.out

18 changes: 18 additions & 0 deletions cdk_java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Welcome to your CDK Java project!

This is a blank project for CDK development with Java.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests.

## Useful commands

* `mvn package` compile and run tests
* `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!
68 changes: 68 additions & 0 deletions cdk_java/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"app": "mvn -e -q compile exec:java",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"target",
"pom.xml",
"src/test"
]
},
"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-iam:standardizedServicePrincipals": 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
}
}
88 changes: 88 additions & 0 deletions cdk_java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>com.myorg</groupId>
<artifactId>cdk_java</artifactId>
<version>0.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cdk.version>2.145.0</cdk.version>
<constructs.version>[10.0.0,11.0.0)</constructs.version>
<junit.version>5.7.1</junit.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<mainClass>com.myorg.CdkJavaApp</mainClass>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- AWS Cloud Development Kit -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>aws-cdk-lib</artifactId>
<version>${cdk.version}</version>
</dependency>

<dependency>
<groupId>software.constructs</groupId>
<artifactId>constructs</artifactId>
<version>${constructs.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.12.738</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.738</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-cloudfront -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cloudfront</artifactId>
<version>1.12.738</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-iam -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-iam</artifactId>
<version>1.12.738</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
42 changes: 42 additions & 0 deletions cdk_java/src/main/java/com/myorg/CdkJavaApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.myorg;

import software.amazon.awscdk.App;
import software.amazon.awscdk.Environment;
import software.amazon.awscdk.StackProps;

import java.util.Arrays;

public class CdkJavaApp {
public static void main(final String[] args) {
App app = new App();

new CdkJavaStack(app, "CdkJavaStack", StackProps.builder()
// 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 block to specialize this stack for the AWS Account
// and Region that are implied by the current CLI configuration.
/*
.env(Environment.builder()
.account(System.getenv("CDK_DEFAULT_ACCOUNT"))
.region(System.getenv("CDK_DEFAULT_REGION"))
.build())
*/

// Uncomment the next block if you know exactly what Account and Region you
// want to deploy the stack to.
/*
.env(Environment.builder()
.account("123456789012")
.region("us-east-1")
.build())
*/

// For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
.build());

app.synth();
}
}

73 changes: 73 additions & 0 deletions cdk_java/src/main/java/com/myorg/CdkJavaStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.myorg;

import software.amazon.awscdk.services.cloudfront.*;
import software.amazon.awscdk.services.iam.Effect;
import software.amazon.awscdk.services.iam.PolicyStatement;
import software.amazon.awscdk.services.s3.Bucket;
import software.amazon.awscdk.services.s3.BucketAccessControl;
import software.amazon.awscdk.services.s3.deployment.BucketDeployment;
import software.amazon.awscdk.services.s3.deployment.Source;
import software.constructs.Construct;
import software.amazon.awscdk.Stack;
import software.amazon.awscdk.StackProps;


import java.util.Collections;
import java.util.List;
// import software.amazon.awscdk.Duration;
// import software.amazon.awscdk.services.sqs.Queue;

public class CdkJavaStack extends Stack {
public CdkJavaStack(final Construct scope, final String id) {
this(scope, id, null);
}

public CdkJavaStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);

// The code that defines your stack goes here

// example resource
// final Queue queue = Queue.Builder.create(this, "CdkJavaQueue")
// .visibilityTimeout(Duration.seconds(300))
// .build();

Bucket myBucket = Bucket.Builder.create(this, "MyBucket")
.versioned(false)
.bucketName("rs-spa")
.websiteIndexDocument("index.html")
.websiteErrorDocument("index.html")
.publicReadAccess(false)
.accessControl(BucketAccessControl.PRIVATE)
.build();

OriginAccessIdentity originAccessIdentity = OriginAccessIdentity.Builder.create(this, "OAI")
.comment("OAI for my SPA")
.build();

myBucket.addToResourcePolicy(PolicyStatement.Builder.create()
.effect(Effect.ALLOW)
.principals(Collections.singletonList(originAccessIdentity.getGrantPrincipal()))
.actions(Collections.singletonList("s3:GetObject"))
.resources(Collections.singletonList(myBucket.arnForObjects("*")))
.build());

CloudFrontWebDistribution distribution = CloudFrontWebDistribution.Builder.create(this, "SiteDistribution")
.originConfigs(Collections.singletonList(
SourceConfiguration.builder()
.s3OriginSource(S3OriginConfig.builder()
.s3BucketSource(myBucket)
.originAccessIdentity(originAccessIdentity)
.build())
.behaviors(Collections.singletonList(Behavior.builder().isDefaultBehavior(true).build()))
.build()))
.build();

BucketDeployment.Builder.create(this, "DeployWebsite")
.sources(Collections.singletonList(Source.asset("../dist")))
.destinationBucket(myBucket)
.distribution(distribution)
.distributionPaths(Collections.singletonList("/*")) // Инвалидация всех путей
.build();
}
}
26 changes: 26 additions & 0 deletions cdk_java/src/test/java/com/myorg/CdkJavaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// package com.myorg;

// import software.amazon.awscdk.App;
// import software.amazon.awscdk.assertions.Template;
// import java.io.IOException;

// import java.util.HashMap;

// import org.junit.jupiter.api.Test;

// example test. To run these tests, uncomment this file, along with the
// example resource in java/src/main/java/com/myorg/CdkJavaStack.java
// public class CdkJavaTest {

// @Test
// public void testStack() throws IOException {
// App app = new App();
// CdkJavaStack stack = new CdkJavaStack(app, "test");

// Template template = Template.fromStack(stack);

// template.hasResourceProperties("AWS::SQS::Queue", new HashMap<String, Number>() {{
// put("VisibilityTimeout", 300);
// }});
// }
// }
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"scripts": {
"start": "vite",
"build": "tsc && vite build",
"deploy": "npm run build && cd cdk_java && cdk deploy",
"destroy": "cd cdk_java && cdk destroy -f",
"preview": "npm run build && vite preview",
"test": "vitest",
"test:ui": "vitest --ui",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/apiPaths.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const API_PATHS = {
product: "https://.execute-api.eu-west-1.amazonaws.com/dev",
product: "https://wa015rf5vk.execute-api.eu-central-1.amazonaws.com/prod/",
order: "https://.execute-api.eu-west-1.amazonaws.com/dev",
import: "https://.execute-api.eu-west-1.amazonaws.com/dev",
bff: "https://.execute-api.eu-west-1.amazonaws.com/dev",
Expand Down
6 changes: 3 additions & 3 deletions src/queries/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useAvailableProducts() {
"available-products",
async () => {
const res = await axios.get<AvailableProduct[]>(
`${API_PATHS.bff}/product/available`
`${API_PATHS.product}/products`
);
return res.data;
}
Expand All @@ -29,7 +29,7 @@ export function useAvailableProduct(id?: string) {
["product", { id }],
async () => {
const res = await axios.get<AvailableProduct>(
`${API_PATHS.bff}/product/${id}`
`${API_PATHS.product}/products/${id}`
);
return res.data;
},
Expand All @@ -48,7 +48,7 @@ export function useRemoveProductCache() {

export function useUpsertAvailableProduct() {
return useMutation((values: AvailableProduct) =>
axios.put<AvailableProduct>(`${API_PATHS.bff}/product`, values, {
axios.post<AvailableProduct>(`${API_PATHS.product}/products`, values, {
headers: {
Authorization: `Basic ${localStorage.getItem("authorization_token")}`,
},
Expand Down