# FunctionUrlCorsOptions

Specifies a cross-origin access property for a function URL.

- Source: [`aws-lambda/lib/function-url.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda/lib/function-url.ts#L90)
- Type last changed: v2.21.0 · 22 Apr 2022

## Example

TypeScript:

```ts
declare const fn: lambda.Function;

fn.addFunctionUrl({
  authType: lambda.FunctionUrlAuthType.NONE,
  cors: {
    // Allow this to be called from websites on https://example.com.
    // Can also be ['*'] to allow all domain.
    allowedOrigins: ['https://example.com'],

    // More options are possible here, see the documentation for FunctionUrlCorsOptions
  },
});
```

Python:

```python
# fn: lambda.Function

fn.add_function_url(
    auth_type=lambda_.FunctionUrlAuthType.NONE,
    cors=lambda.FunctionUrlCorsOptions(
        # Allow this to be called from websites on https://example.com.
        # Can also be ['*'] to allow all domain.
        allowed_origins=["https://example.com"]
    )
)
```

Java:

```java
Function fn;

fn.addFunctionUrl(FunctionUrlOptions.builder()
        .authType(FunctionUrlAuthType.NONE)
        .cors(FunctionUrlCorsOptions.builder()
                // Allow this to be called from websites on https://example.com.
                // Can also be ['*'] to allow all domain.
                .allowedOrigins(List.of("https://example.com"))
                .build())
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Function fn;

fn.AddFunctionUrl(new FunctionUrlOptions {
    AuthType = FunctionUrlAuthType.NONE,
    Cors = new FunctionUrlCorsOptions {
        // Allow this to be called from websites on https://example.com.
        // Can also be ['*'] to allow all domain.
        AllowedOrigins = new [] { "https://example.com" }
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var fn Function

fn.AddFunctionUrl(&FunctionUrlOptions{
	AuthType: lambda.FunctionUrlAuthType_NONE,
	Cors: &FunctionUrlCorsOptions{
		// Allow this to be called from websites on https://example.com.
		// Can also be ['*'] to allow all domain.
		AllowedOrigins: []*string{
			jsii.String("https://example.com"),
		},
	},
})
```

## Properties

- `allowCredentials`: boolean = false — Whether to allow cookies or other credentials in requests to your function URL.

- `allowedHeaders`: string[] — Headers that are specified in the Access-Control-Request-Headers header.

  **Default:** No headers allowed.

- `allowedMethods`: [HttpMethod](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.HttpMethod.html)[] = [HttpMethod.ALL] — An HTTP method that you allow the origin to execute.

- `allowedOrigins`: string[] — One or more origins you want customers to be able to access the bucket from.

  **Default:** No origins allowed.

- `exposedHeaders`: string[] — One or more headers in the response that you want customers to be able to access from their applications.

  **Default:** No headers exposed.

- `maxAge`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The time in seconds that your browser is to cache the preflight response for the specified resource.

  **Default:** Browser default of 5 seconds.
