Skip to content

Commit

Permalink
Merge branch 'main' into huijbers/assertions-string
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 10, 2023
2 parents 2e5202b + ea06f7d commit 36b6460
Show file tree
Hide file tree
Showing 36 changed files with 41,062 additions and 2,475 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/issue-label-assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ env:
{"area":"@aws-cdk/aws-s3outposts","keywords":["aws-s3outposts","s3outposts"],"labels":["@aws-cdk/aws-s3outposts"]},
{"area":"@aws-cdk/aws-sagemaker","keywords":["aws-sagemaker","sagemaker"],"labels":["@aws-cdk/aws-sagemaker"]},
{"area":"@aws-cdk/aws-sam","keywords":["serverless-application-model","aws-sam","sam"],"labels":["@aws-cdk/aws-sam"]},
{"area":"@aws-cdk/aws-scheduler","keywords":["aws-scheduler","scheduler"],"labels":["@aws-cdk/aws-scheduler"]},
{"area":"@aws-cdk/aws-scheduler-targets","keywords":["aws-scheduler-targets","scheduler-targets"],"labels":["@aws-cdk/aws-scheduler-targets"]},
{"area":"@aws-cdk/aws-sdb","keywords":["simpledb","aws-sdb","sdb"],"labels":["@aws-cdk/aws-sdb"]},
{"area":"@aws-cdk/aws-secretsmanager","keywords":["secret","aws-secretsmanager","secrets-manager"],"labels":["@aws-cdk/aws-secretsmanager"]},
{"area":"@aws-cdk/aws-securityhub","keywords":["aws-securityhub","security-hub"],"labels":["@aws-cdk/aws-securityhub"]},
Expand Down
18 changes: 10 additions & 8 deletions packages/@aws-cdk/aws-glue-alpha/lib/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ export interface SparkUIProps {
/**
* The bucket where the Glue job stores the logs.
*
* @default a new bucket will be created.
* @default - a new bucket will be created.
*/
readonly bucket?: s3.IBucket;

/**
* The path inside the bucket (objects prefix) where the Glue job stores the logs.
* Use format `'/foo/bar'`
* Use format `'foo/bar/'`
*
* @default - the logs will be written at the root of the bucket
*/
Expand All @@ -406,13 +406,15 @@ export interface SparkUIProps {
export interface SparkUILoggingLocation {
/**
* The bucket where the Glue job stores the logs.
*
* @default - a new bucket will be created.
*/
readonly bucket: s3.IBucket;

/**
* The path inside the bucket (objects prefix) where the Glue job stores the logs.
*
* @default '/' - the logs will be written at the root of the bucket
* @default - the logs will be written at the root of the bucket
*/
readonly prefix?: string;
}
Expand Down Expand Up @@ -840,12 +842,12 @@ export class Job extends JobBase {

const errors: string[] = [];

if (!prefix.startsWith('/')) {
errors.push('Prefix must begin with \'/\'');
if (prefix.startsWith('/')) {
errors.push('Prefix must not begin with \'/\'');
}

if (prefix.endsWith('/')) {
errors.push('Prefix must not end with \'/\'');
if (!prefix.endsWith('/')) {
errors.push('Prefix must end with \'/\'');
}

if (errors.length > 0) {
Expand All @@ -854,7 +856,7 @@ export class Job extends JobBase {
}

private cleanPrefixForGrant(prefix?: string): string | undefined {
return prefix !== undefined ? prefix.slice(1) + '/*' : undefined;
return prefix !== undefined ? `${prefix}*` : undefined;
}

private setupContinuousLogging(role: iam.IRole, props: ContinuousLoggingProps) {
Expand Down
12 changes: 6 additions & 6 deletions packages/@aws-cdk/aws-glue-alpha/test/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,14 @@ describe('Job', () => {
});
describe('with bucket and path provided', () => {
const sparkUIBucketName = 'sparkbucketname';
const prefix = '/foob/bart';
const badPrefix = 'foob/bart/';
const prefix = 'foob/bart/';
const badPrefix = '/foob/bart';
let sparkUIBucket: s3.IBucket;

const expectedErrors = [
`Invalid prefix format (value: ${badPrefix})`,
'Prefix must begin with \'/\'',
'Prefix must not end with \'/\'',
'Prefix must not begin with \'/\'',
'Prefix must end with \'/\'',
].join(EOL);
it('fails if path is mis-formatted', () => {
expect(() => new glue.Job(stack, 'BadPrefixJob', {
Expand Down Expand Up @@ -699,7 +699,7 @@ describe('Job', () => {
[
'arn:',
{ Ref: 'AWS::Partition' },
`:s3:::sparkbucketname${prefix}/*`,
`:s3:::sparkbucketname/${prefix}*`,
],
],
},
Expand All @@ -718,7 +718,7 @@ describe('Job', () => {
Template.fromStack(stack).hasResourceProperties('AWS::Glue::Job', {
DefaultArguments: {
'--enable-spark-ui': 'true',
'--spark-event-logs-path': `s3://${sparkUIBucketName}${prefix}`,
'--spark-event-logs-path': `s3://${sparkUIBucketName}/${prefix}`,
},
});
});
Expand Down
29 changes: 28 additions & 1 deletion packages/@aws-cdk/aws-lambda-python-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Packaging is executed using the `Packaging` class, which:

**Excluding source files**

You can exclude files from being copied using the optional bundling string array parameter `assetExcludes`
You can exclude files from being copied using the optional bundling string array parameter `assetExcludes`:

```ts
new python.PythonFunction(this, 'function', {
Expand All @@ -124,6 +124,33 @@ new python.PythonFunction(this, 'function', {
});
```

**Including hashes**

You can include hashes in `poetry` using the optional boolean parameter `poetryIncludeHashes`:

```ts
new python.PythonFunction(this, 'function', {
entry: '/path/to/poetry-function',
runtime: Runtime.PYTHON_3_8,
bundling: {
poetryIncludeHashes: true,
},
});
```

**Excluding URLs**

You can exclude URLs in `poetry` using the optional boolean parameter `poetryWithoutUrls`:

```ts
new python.PythonFunction(this, 'function', {
entry: '/path/to/poetry-function',
runtime: Runtime.PYTHON_3_8,
bundling: {
poetryWithoutUrls: true,
},
});
```

## Custom Bundling

Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-lambda-python-alpha/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class Bundling implements CdkBundlingOptions {
outputPathSuffix = '',
image,
poetryIncludeHashes,
poetryWithoutUrls,
commandHooks,
assetExcludes = [],
} = props;
Expand All @@ -93,6 +94,7 @@ export class Bundling implements CdkBundlingOptions {
inputDir: AssetStaging.BUNDLING_INPUT_DIR,
outputDir: outputPath,
poetryIncludeHashes,
poetryWithoutUrls,
commandHooks,
assetExcludes,
});
Expand All @@ -117,7 +119,7 @@ export class Bundling implements CdkBundlingOptions {
}

private createBundlingCommand(options: BundlingCommandOptions): string[] {
const packaging = Packaging.fromEntry(options.entry, options.poetryIncludeHashes);
const packaging = Packaging.fromEntry(options.entry, options.poetryIncludeHashes, options.poetryWithoutUrls);
let bundlingCommands: string[] = [];
bundlingCommands.push(...options.commandHooks?.beforeBundling(options.inputDir, options.outputDir) ?? []);
const exclusionStr = options.assetExcludes?.map(item => `--exclude='${item}'`).join(' ');
Expand All @@ -140,6 +142,7 @@ interface BundlingCommandOptions {
readonly outputDir: string;
readonly assetExcludes?: string[];
readonly poetryIncludeHashes?: boolean;
readonly poetryWithoutUrls?: boolean;
readonly commandHooks?: ICommandHooks;
}

Expand Down
16 changes: 12 additions & 4 deletions packages/@aws-cdk/aws-lambda-python-alpha/lib/packaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ export interface PoetryPackagingProps {
* export with a hash.
*
* @see https://github.com/aws/aws-cdk/issues/19232
* @default Hashes are NOT included in the exported `requirements.txt` file
* @default Hashes are NOT included in the exported `requirements.txt` file.
*/
readonly poetryIncludeHashes?: boolean;

/**
* Whether to export Poetry dependencies with source repository urls.
*
* @default URLs are included in the exported `requirements.txt` file.
*/
readonly poetryWithoutUrls?: boolean;
}

export class Packaging {
Expand Down Expand Up @@ -65,6 +72,7 @@ export class Packaging {
exportCommand: [
'poetry', 'export',
...props?.poetryIncludeHashes ? [] : ['--without-hashes'],
...props?.poetryWithoutUrls ? ['--without-urls'] : [],
'--with-credentials',
'--format', DependenciesFile.PIP,
'--output', DependenciesFile.PIP,
Expand All @@ -79,11 +87,11 @@ export class Packaging {
return new Packaging({ dependenciesFile: DependenciesFile.NONE });
}

public static fromEntry(entry: string, poetryIncludeHashes?: boolean): Packaging {
public static fromEntry(entry: string, poetryIncludeHashes?: boolean, poetryWithoutUrls?: boolean): Packaging {
if (fs.existsSync(path.join(entry, DependenciesFile.PIPENV))) {
return this.withPipenv();
} if (fs.existsSync(path.join(entry, DependenciesFile.POETRY))) {
return this.withPoetry({ poetryIncludeHashes });
return this.withPoetry({ poetryIncludeHashes, poetryWithoutUrls });
} else if (fs.existsSync(path.join(entry, DependenciesFile.PIP))) {
return this.withPip();
} else {
Expand All @@ -97,4 +105,4 @@ export class Packaging {
this.dependenciesFile = props.dependenciesFile;
this.exportCommand = props.exportCommand;
}
}
}
15 changes: 11 additions & 4 deletions packages/@aws-cdk/aws-lambda-python-alpha/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ export interface BundlingOptions extends DockerRunOptions {
readonly poetryIncludeHashes?: boolean;

/**
* List of file patterns to exclude when copying assets from source for bundling.
*
* @default - Empty list
*/
* Whether to export Poetry dependencies with source repository urls.
*
* @default URLs are included in the exported `requirements.txt` file.
*/
readonly poetryWithoutUrls?: boolean;

/**
* List of file patterns to exclude when copying assets from source for bundling.
*
* @default - Empty list
*/
readonly assetExcludes?: string[];

/**
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-lambda-python-alpha/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,34 @@ test('Bundling a function with poetry dependencies, with hashes', () => {
expect(files).toContain('.ignorefile');
});

test('Bundling a function with poetry dependencies, without urls', () => {
const entry = path.join(__dirname, 'lambda-handler-poetry');

const assetCode = Bundling.bundle({
entry: path.join(entry, '.'),
runtime: Runtime.PYTHON_3_9,
architecture: Architecture.X86_64,
outputPathSuffix: 'python',
poetryWithoutUrls: true,
});

expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({
bundling: expect.objectContaining({
command: [
'bash', '-c',
'rsync -rLv /asset-input/ /asset-output/python && cd /asset-output/python && poetry export --without-hashes --without-urls --with-credentials --format requirements.txt --output requirements.txt && python -m pip install -r requirements.txt -t /asset-output/python',
],
}),
}));

const files = fs.readdirSync(assetCode.path);
expect(files).toContain('index.py');
expect(files).toContain('pyproject.toml');
expect(files).toContain('poetry.lock');
// Contains hidden files.
expect(files).toContain('.ignorefile');
});

test('Bundling a function with custom bundling image', () => {
const entry = path.join(__dirname, 'lambda-handler-custom-build');
const image = DockerImage.fromBuild(path.join(entry));
Expand Down
Loading

0 comments on commit 36b6460

Please sign in to comment.