Я думаю, что получил:
Java код
package YOURPACKAGENAMEHERE;
import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.Stack;
import java.util.UUID;
import software.amazon.awscdk.core.Duration;
import software.amazon.awscdk.services.lambda.Alias;
import software.amazon.awscdk.services.lambda.AliasProps;
import software.amazon.awscdk.services.lambda.Code;
import software.amazon.awscdk.services.lambda.Function;
import software.amazon.awscdk.services.lambda.IFunction;
import software.amazon.awscdk.services.lambda.Runtime;
import software.amazon.awscdk.services.lambda.SingletonFunction;
import software.amazon.awscdk.services.lambda.Version;
import software.amazon.awscdk.services.lambda.VersionProps;
import software.amazon.awscdk.services.iam.Role;
public class JavacdexampleStack extends Stack {
public JavacdexampleStack(final Construct scope, final String id) {
super(scope, id);
//create Lambda function
SingletonFunction lambdaFunction =
SingletonFunction.Builder.create(this, "cdk-lambda-example")
.description("Lambda which prints \"I'm running\"")
.code(Code.fromInline("def main(event, context):\n" + " print(\"I'm running!\")\n"))
.handler("index.main")
.timeout(Duration.seconds(300))
.runtime(Runtime.PYTHON_3_7)
.uuid(UUID.randomUUID().toString())
.role(Role.fromRoleArn(this, "roleId", "arn:aws:iam::111122223333:role/116CD745-C8DA-4569-8058-828EFA93E6D7"))//replace with your execution role or create one in cdk
.build();
IFunction lambda = Function.fromFunctionArn(this, "functionId", lambdaFunction.getFunctionArn());
//create version for alias to be assigned to
VersionProps versionprop = new VersionProps.Builder()
.lambda(lambda)
//assign version which the alias points to with provisioned concurrency
.provisionedConcurrentExecutions(5)
.build();
Version version = new Version(this, "versionId", versionprop);
//create alias
AliasProps aliasprops = new AliasProps.Builder()
.aliasName("YourAliasNameHere")
.version(version)
.build();
Alias alias = new Alias(this,"aliasId", aliasprops);
}
}
ВЫХОД :
предприняты предварительные шаги
# assumes npm and mvn are installed
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
npm install -g aws-cdk
cdk --version
# pasting here for visability on which version I used
1.22.0 (build 309ac1b)
mkdir javacdkexample
cd javacdkexample
cdk init --language java
# recommended to run after creating the project from docs
# https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html#getting_started_update
mvn versions:use-latest-versions
пом. xml
<dependencies>
<!-- AWS Cloud Development Kit -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>core</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>lambda</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>events-targets</artifactId>
<version>1.22.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>