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

feat(efs): import access point - fromAccessPointAttributes() #10712

Merged
merged 9 commits into from
Nov 11, 2020

Conversation

DaWyz
Copy link
Contributor

@DaWyz DaWyz commented Oct 6, 2020

Cannot use efs.AccessPoint.fromAccessPointId() with lambda.FileSystem.fromEfsAccessPoint(). the former returns an IAccessPoint when the later expect an AccessPoint. I think following the CDK guidelines, lambda.FileSystem.fromEfsAccessPoint() should expect an IAccessPoint, not an AccessPoint.

Argument of type IAccessPoint is not assignable to parameter of type AccessPoint.

Solution


Add a new import method to the AccessPoint class called fromAccessPointAttributes() allowing to pass a fileSystem as an attribute.

Closes #10711.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Also update aws-lambda filesystem 'fromEfsAccessPoint' to expect an IAccessPoint instead of AccessPoint
@DaWyz
Copy link
Contributor Author

DaWyz commented Oct 9, 2020

I just looked into it again. I'm not sure it makes sense to me anymore. Also, the issue is still valid, the implementation I made doesn't seem like the right way to do it. If you think the same, I'm happy to discuss about the implementation and close this Pull Request.

I'm just confused about the FileSystem class in the @aws-cdk/aws-lambda and I'm wondering if it's not kind of redundant.

Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaWyz

awesome first pass!! thanks for getting the ball rolling on this. I have some thoughts that I'd love to work in before merging this in. The most important one is creating a class that represents an imported file system. Take a look at the example of how it's done in rds and let me know what you think!

packages/@aws-cdk/aws-efs/lib/access-point.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/lib/access-point.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/lib/access-point.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/lib/access-point.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/lib/access-point.ts Show resolved Hide resolved
packages/@aws-cdk/aws-efs/lib/access-point.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed shivlaks’s stale review October 23, 2020 05:13

Pull request has been modified.

@DaWyz
Copy link
Contributor Author

DaWyz commented Oct 26, 2020

@DaWyz

awesome first pass!! thanks for getting the ball rolling on this. I have some thoughts that I'd love to work in before merging this in. The most important one is creating a class that represents an imported file system. Take a look at the example of how it's done in rds and let me know what you think!

@shivlaks We could extract the existing imported file system class if it's what you mean. I can do the same for the AccessPoint as well.

About the IFileSystem property in the IAccessPoint, I made it mandatory because of the lambda efs implementation. This is the only place where the AccessPoint class is used and it needs the FileSystem to be able to setup the ingress rules.

So, at the moment, we cannot import an existing access point since it doesn't have the fileSystem property when using fromAccessPointId. I guess we could make the FileSystem property of fromAccessPointAttributes optional by updating the code in the lambda efs implementation to check for ap.fileSystem presence and make if fail with a nice error message in case it's missing.

Also, I dropped the existing fromAccessPointId method and I don't think I should. Making the fileSystem property optional would allow me to add fromAccessPointId method back.

Let me know what you think and I can update the code accordingly.

@gitpod-io
Copy link

gitpod-io bot commented Oct 28, 2020

@shivlaks
Copy link
Contributor

@shivlaks We could extract the existing imported file system class if it's what you mean. I can do the same for the AccessPoint as well.

yep that is what I mean. extract to ImportedFileSystem or so that implements IFileSystem and we just return new ImportedFileSystem in the fromFileSystemAttributes method

About the IFileSystem property in the IAccessPoint, I made it mandatory because of the lambda efs implementation. This is the only place where the AccessPoint class is used and it needs the FileSystem to be able to setup the ingress rules.

got it, thanks for explaining! might be worth a comment.

So, at the moment, we cannot import an existing access point since it doesn't have the fileSystem property when using fromAccessPointId. I guess we could make the FileSystem property of fromAccessPointAttributes optional by updating the code in the lambda efs implementation to check for ap.fileSystem presence and make if fail with a nice error message in case it's missing.

It seems reasonable to me. Adding the fileSystem property would have to be optional as you've suggested because the alternative is a breaking change and the lambda module is stable.
I'd defer to @nija-at on whether that's an approach he's comfortable with as he's the primary maintainer of the module.

Also, I dropped the existing fromAccessPointId method and I don't think I should. Making the fileSystem property optional would allow me to add fromAccessPointId method back.

I agree, let's avoid dropping the method.

Let me know what you think and I can update the code accordingly.

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions below.

packages/@aws-cdk/aws-efs/lib/access-point.ts Show resolved Hide resolved
/**
* The efs filesystem
*/
readonly fileSystem?: IFileSystem;
Copy link
Contributor

@nija-at nija-at Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about make this mandatory and throw an error in the implementation of fromAccessPointId()?

The error message can be "fileSystem is not available when 'fromAccessPointId()' is used. Use 'fromAccessPointAttributes()' instead"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nija-at, that would also be a breaking change as well, right ?

I'm wondering if there is a use-case (outside of EFS for lambda) where we would need to import an AccessPoint without having the need for FileSystem ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

efs is an experimental module. Breaking changes are acceptable as long as they are called out in the commit description.

I'm wondering if there is a use-case (outside of EFS for lambda) where we would need to import an AccessPoint without having the need for FileSystem ?

In such cases exist, the fromAccessPointId() API can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I didn't get the idea of how to implement this at start. I think I'm good now. I'm doing the same as in the rds imported cluster and throw the exception on the Getter when fileSystem is not present.. See below. Will update the PR.

class ImportedAccessPoint extends AccessPointBase {
  public readonly accessPointId: string;
  public readonly accessPointArn: string;
  private readonly _fileSystem?: IFileSystem;

  constructor(scope: Construct, id: string, attrs: AccessPointAttributes) {
    super(scope, id);

    if (!attrs.accessPointId) {
      if (!attrs.accessPointArn) {
        throw new Error('One of accessPointId or AccessPointArn is required!');
      }

      this.accessPointArn = attrs.accessPointArn;
      let maybeApId = Stack.of(scope).parseArn(attrs.accessPointArn).resourceName;

      if (!maybeApId) {
        throw new Error('ARN for AccessPoint must provide the resource name.');
      }

      this.accessPointId = maybeApId;
    } else {
      if (attrs.accessPointArn) {
        throw new Error('Only one of accessPointId or AccessPointArn can be provided!');
      }

      this.accessPointId = attrs.accessPointId;
      this.accessPointArn = Stack.of(scope).formatArn({
        service: 'elasticfilesystem',
        resource: 'access-point',
        resourceName: attrs.accessPointId,
      });
    }

    this._fileSystem = attrs.fileSystem;
  }

  public get fileSystem() {
    if (!this._fileSystem) {
      throw new Error("fileSystem is not available when 'fromAccessPointId()' is used. Use 'fromAccessPointAttributes()' instead");
    }

    return this._fileSystem;
  }
}

packages/@aws-cdk/aws-efs/lib/access-point.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/lib/access-point.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-efs/README.md Outdated Show resolved Hide resolved
@nija-at nija-at changed the title fix(aws-efs): add fromAccessPointAttributes to the AccessPoint class feat(efs): access point import - fromAccessPointAttributes() Oct 28, 2020
@nija-at nija-at changed the title feat(efs): access point import - fromAccessPointAttributes() feat(efs): import access point - fromAccessPointAttributes() Oct 28, 2020
@mergify mergify bot dismissed nija-at’s stale review October 29, 2020 03:35

Pull request has been modified.

@shivlaks shivlaks added the pr/do-not-merge This PR should not be merged at this time. label Nov 11, 2020
Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaWyz - changes look good to me!
i added a do-not-merge so @nija-at can also take a look

@shivlaks
Copy link
Contributor

confirmed with @nija-at that we shouldn't wait on another review, thanks for the contribution @DaWyz !!

@shivlaks shivlaks removed the pr/do-not-merge This PR should not be merged at this time. label Nov 11, 2020
@mergify
Copy link
Contributor

mergify bot commented Nov 11, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: b5fc34d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Nov 11, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit ec72c85 into aws:master Nov 11, 2020
@DaWyz
Copy link
Contributor Author

DaWyz commented Nov 11, 2020

confirmed with @nija-at that we shouldn't wait on another review, thanks for the contribution @DaWyz !!

No problem! Happy to help! I'm sure you guys are extremely busy with CDK so thank you for taking the time to review the PRs! Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-efs] Cannot import an existing EFS Access Point to use with a lambda function
4 participants