Skip to content

Commit

Permalink
Merge branch 'main' into mikewrighton-26839-2
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 22, 2023
2 parents 76c1f47 + 193cd3f commit d80af5c
Show file tree
Hide file tree
Showing 45 changed files with 1,631 additions and 294 deletions.
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"tools/@aws-cdk/prlint",
"tools/@aws-cdk/spec2cdk",
"tools/@aws-cdk/yarn-cling",
"tools/@aws-cdk/lazify",
"scripts/@aws-cdk/script-tests"
],
"rejectCycles": true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"tools/@aws-cdk/prlint",
"tools/@aws-cdk/spec2cdk",
"tools/@aws-cdk/yarn-cling",
"tools/@aws-cdk/lazify",
"scripts/@aws-cdk/script-tests"
],
"nohoist": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { integTest, withTemporaryDirectory, ShellHelper, withPackages } from '../../lib';

['app', 'sample-app'].forEach(template => {
Expand All @@ -13,3 +15,43 @@ import { integTest, withTemporaryDirectory, ShellHelper, withPackages } from '..
await shell.shell(['cdk', 'synth']);
})));
});

integTest('Test importing CDK from ESM', withTemporaryDirectory(withPackages(async (context) => {
// Use 'cdk init -l=javascript' to get set up, but use a different file
const shell = ShellHelper.fromContext(context);
await context.packages.makeCliAvailable();

await shell.shell(['cdk', 'init', '-l', 'javascript', 'app']);

// Rewrite some files
await fs.writeFile(path.join(context.integTestDir, 'new-entrypoint.mjs'), `
// Test two styles of imports
import { Stack, aws_sns as sns, aws_sns_subscriptions as subs, aws_sqs as sqs } from 'aws-cdk-lib';
import * as cdk from 'aws-cdk-lib';
class TestjsStack extends Stack {
constructor(scope, id, props) {
super(scope, id, props);
const queue = new sqs.Queue(this, 'TestjsQueue', {
visibilityTimeout: cdk.Duration.seconds(300)
});
const topic = new sns.Topic(this, 'TestjsTopic');
topic.addSubscription(new subs.SqsSubscription(queue));
}
}
const app = new cdk.App();
new TestjsStack(app, 'TestjsStack');
`, { encoding: 'utf-8' });

// Rewrite 'cdk.json' to use new entrypoint
const cdkJson = await fs.readJson(path.join(context.integTestDir, 'cdk.json'));
cdkJson.app = 'node new-entrypoing.mjs';
await fs.writeJson(path.join(context.integTestDir, 'cdk.json'), cdkJson);

await shell.shell(['cdk', 'synth']);

})));
20 changes: 15 additions & 5 deletions packages/@aws-cdk/aws-scheduler-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ You can choose from three schedule types when configuring your schedule: rate-ba
Both rate-based and cron-based schedules are recurring schedules. You can configure each recurring schedule type using a schedule expression. For
cron-based schedule you can specify a time zone in which EventBridge Scheduler evaluates the expression.


> ScheduleExpression should be used together with class Schedule, which is not yet implemented.
[comment]: <> (TODO: Switch to `ts` once Schedule is implemented)

```ts
declare const target: targets.LambdaInvoke;

Expand Down Expand Up @@ -129,6 +124,21 @@ new Schedule(this, 'Schedule', {
});
```

### Disabling Schedules

By default, a schedule will be enabled. You can disable a schedule by setting the `enabled` property to false:

```ts
declare const target: targets.LambdaInvoke;

new Schedule(this, 'Schedule', {
schedule: ScheduleExpression.rate(Duration.minutes(10)),
target: target,
enabled: false,
});
```


## Scheduler Targets

The `@aws-cdk/aws-schedule-targets-alpha` module includes classes that implement the `IScheduleTarget` interface for
Expand Down
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ export interface ScheduleProps {
/**
* The schedule's group.
*
* @deafult - By default a schedule will be associated with the `default` group.
* @default - By default a schedule will be associated with the `default` group.
*/
readonly group?: IGroup;

/**
* Indicates whether the schedule is enabled.
* @default true
*/
readonly enabled?: boolean;
}

/**
Expand Down Expand Up @@ -95,6 +101,7 @@ export class Schedule extends Resource implements ISchedule {
scheduleExpression: props.schedule.expressionString,
scheduleExpressionTimezone: props.schedule.timeZone?.timezoneName,
groupName: this.group?.groupName,
state: (props.enabled ?? true) ? 'ENABLED' : 'DISABLED',
target: {
arn: targetConfig.arn,
roleArn: targetConfig.role.roleArn,
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-scheduler-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^29.5.5",
"aws-cdk-lib": "0.0.0",
"constructs": "^10.0.0"
"constructs": "^10.0.0",
"@aws-cdk/integ-tests-alpha": "0.0.0"
},
"dependencies": {},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "34.0.0",
"files": {
"bbcd00ec8f22ebae1e8018bdae1226dbbdf643fd8c5453daf208abedd325db6c": {
"source": {
"path": "aws-cdk-scheduler-schedule.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "bbcd00ec8f22ebae1e8018bdae1226dbbdf643fd8c5453daf208abedd325db6c.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"Resources": {
"FunctionServiceRole675BB04A": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"Function76856677": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "foo"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"FunctionServiceRole675BB04A",
"Arn"
]
},
"Runtime": "nodejs18.x"
},
"DependsOn": [
"FunctionServiceRole675BB04A"
]
},
"Role1ABCC5F0": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "scheduler.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"DefaultSchedule597B0B2C": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
"FlexibleTimeWindow": {
"Mode": "OFF"
},
"ScheduleExpression": "rate(12 hours)",
"State": "ENABLED",
"Target": {
"Arn": {
"Fn::GetAtt": [
"Function76856677",
"Arn"
]
},
"RoleArn": {
"Fn::GetAtt": [
"Role1ABCC5F0",
"Arn"
]
}
}
}
},
"DisabledScheduleA1DF7F0F": {
"Type": "AWS::Scheduler::Schedule",
"Properties": {
"FlexibleTimeWindow": {
"Mode": "OFF"
},
"ScheduleExpression": "rate(12 hours)",
"State": "DISABLED",
"Target": {
"Arn": {
"Fn::GetAtt": [
"Function76856677",
"Arn"
]
},
"RoleArn": {
"Fn::GetAtt": [
"Role1ABCC5F0",
"Arn"
]
}
}
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"34.0.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "34.0.0",
"testCases": {
"integtest-schedule/DefaultTest": {
"stacks": [
"aws-cdk-scheduler-schedule"
],
"assertionStack": "integtest-schedule/DefaultTest/DeployAssert",
"assertionStackName": "integtestscheduleDefaultTestDeployAssert24CB3896"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "34.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "integtestscheduleDefaultTestDeployAssert24CB3896.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Loading

0 comments on commit d80af5c

Please sign in to comment.