Ejemplo n.º 1
0
def lambda_function(
    *,
    bucket_name: Parameter,
    workers_key: Parameter,
    name: str,
    role: iam.Role,
    runtime: str,
    namespace: str,
    module: str,
    memory_size: int,
    timeout: int,
    tags: Tags,
    source_bucket: Optional[Parameter] = None,
) -> awslambda.Function:
    if source_bucket is None:
        source_bucket = bucket_name

    return awslambda.Function(
        name,
        Role=role.get_att("Arn"),
        Code=awslambda.Code(S3Bucket=source_bucket.ref(),
                            S3Key=workers_key.ref()),
        Handler=f"accretion_workers.{namespace}.{module}.lambda_handler",
        Environment=_lambda_environment(bucket_name),
        Runtime=runtime,
        MemorySize=memory_size,
        Timeout=timeout,
        Tags=tags,
    )
Ejemplo n.º 2
0
    def get_auth_at_edge_lambda(self, title: str, description: str,
                                handler: str,
                                role: iam.Role) -> awslambda.Function:
        """Create an Auth@Edge lambda resource.

        Args:
            title: The name of the function in PascalCase.
            description: Description to be displayed in the lambda panel.
            handler: The underscore separated representation
                of the name of the lambda. This handle is used to
                determine the handler for the lambda as well as
                identify the correct Code hook_data information.
            role: The Lambda Execution Role.

        """
        lamb = self.template.add_resource(
            awslambda.Function(
                title,
                DeletionPolicy="Retain",
                Code=self.context.hook_data["aae_lambda_config"][handler],
                Description=description,
                Handler="__init__.handler",
                Role=role.get_att("Arn"),
                Runtime="python3.7",
            ))

        self.template.add_output(
            Output(
                "Lambda%sArn" % title,
                Description="Arn For the %s Lambda Function" % title,
                Value=lamb.get_att("Arn"),
            ))

        return lamb
Ejemplo n.º 3
0
    def create_template(self) -> None:
        """Create a template from the Blueprint."""
        self.template.set_description("Admin role")
        self.template.set_version("2010-09-09")

        role = Role(
            "Role",
            template=self.template,
            AssumeRolePolicyDocument=self.assume_role_policy,
            Description="Admin role",
            ManagedPolicyArns=["arn:aws:iam::aws:policy/AdministratorAccess"],
            MaxSessionDuration=3600,  # 1 hour
            PermissionsBoundary=self.variables["PermissionsBoundary"],
            RoleName=self.role_name or NoValue,
        )
        self.add_output(role.title, role.ref())
        self.add_output(f"{role.title}Arn", role.get_att("Arn"))