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

[POC] Use resource name to have functions in separate stacks. #1981

Draft
wants to merge 1 commit into
base: function-stacks-0
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages/backend-function/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type FunctionProps = {
environment?: Record<string, string | BackendSecret>;
runtime?: NodeVersion;
schedule?: FunctionSchedule | FunctionSchedule[];
resourceGroupName?: string;
};

// @public (undocumented)
Expand Down
10 changes: 8 additions & 2 deletions packages/backend-function/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ export type FunctionProps = {
* schedule: "0 9 ? * 2 *" // every Monday at 9am
*/
schedule?: FunctionSchedule | FunctionSchedule[];

// TODO Naming, but maybe it's not a bad name given this concept exists in plugin types already.
resourceGroupName?: string;
};

/**
Expand Down Expand Up @@ -169,6 +172,7 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> {
environment: this.props.environment ?? {},
runtime: this.resolveRuntime(),
schedule: this.resolveSchedule(),
resourceGroupName: this.props.resourceGroupName ?? 'function',
};
};

Expand Down Expand Up @@ -279,12 +283,14 @@ class FunctionFactory implements ConstructFactory<AmplifyFunction> {
type HydratedFunctionProps = Required<FunctionProps>;

class FunctionGenerator implements ConstructContainerEntryGenerator {
readonly resourceGroupName = 'function';
readonly resourceGroupName: string;

constructor(
private readonly props: HydratedFunctionProps,
private readonly outputStorageStrategy: BackendOutputStorageStrategy<FunctionOutput>
) {}
) {
this.resourceGroupName = props.resourceGroupName;
}

generateContainerEntry = ({
scope,
Expand Down
1 change: 1 addition & 0 deletions test-projects/function-stack-1/amplify/data/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "@aws-amplify/backend";

const testHandler = defineFunction({
resourceGroupName: 'function2'
});

const schema = a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ import {
defineFunction,
} from "@aws-amplify/backend";

export const myApiFunction = defineFunction();
export const myApiFunction = defineFunction({
resourceGroupName: 'function1'
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { defineFunction } from '@aws-amplify/backend';

export const testFunction = defineFunction();
export const testFunction = defineFunction({
resourceGroupName: 'function1'
});

export const myApiFunction = defineFunction({
name: 'api-function',
resourceGroupName: 'function2'
});