

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

# ApiAuth
<a name="sam-property-api-apiauth"></a>

Konfigurieren Sie die Autorisierung, um den Zugriff auf Ihre API-Gateway-API zu kontrollieren.

Weitere Informationen und Beispiele für die Konfiguration des Zugriffs mithilfe von AWS SAM finden Sie unter[Kontrollieren Sie den API-Zugriff mit Ihrer AWS SAM Vorlage](serverless-controlling-access-to-apis.md).

## Syntax
<a name="sam-property-api-apiauth-syntax"></a>

Verwenden Sie die folgende Syntax, um diese Entität in Ihrer Vorlage AWS Serverless Application Model (AWS SAM) zu deklarieren.

### YAML
<a name="sam-property-api-apiauth-syntax.yaml"></a>

```
  AddApiKeyRequiredToCorsPreflight: {{Boolean}}
  [AddDefaultAuthorizerToCorsPreflight](#sam-api-apiauth-adddefaultauthorizertocorspreflight): {{Boolean}}
  [ApiKeyRequired](#sam-api-apiauth-apikeyrequired): {{Boolean}}
  [Authorizers](#sam-api-apiauth-authorizers): {{CognitoAuthorizer | LambdaTokenAuthorizer | LambdaRequestAuthorizer | AWS_IAM}}
  [DefaultAuthorizer](#sam-api-apiauth-defaultauthorizer): {{String}}
  [InvokeRole](#sam-api-apiauth-invokerole): {{String}}
  [ResourcePolicy](#sam-api-apiauth-resourcepolicy): {{ResourcePolicyStatement}}
  [UsagePlan](#sam-api-apiauth-usageplan): {{ApiUsagePlan}}
```

**Anmerkung**  
Die `Authorizers` Eigenschaft beinhaltet`AWS_IAM`, aber dafür ist keine zusätzliche Konfiguration erforderlich`AWS_IAM`. Ein Beispiel finden Sie unter [AWS ICH BIN](#sam-property-api-apiauth--examples--aws_iam).

## Eigenschaften
<a name="sam-property-api-apiauth-properties"></a>

 `AddApiKeyRequiredToCorsPreflight`   <a name="sam-api-apiauth-addapikeyrequiredtocorspreflight"></a>
Wenn die `Cors` Eigenschaften `ApiKeyRequired` und festgelegt sind, führt `AddApiKeyRequiredToCorsPreflight` diese Einstellung dazu, dass der API-Schlüssel der `Options` Eigenschaft hinzugefügt wird.  
*Typ*: Boolesch  
*Required*: No  
*Standardwert*: `True`  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.

 `AddDefaultAuthorizerToCorsPreflight`   <a name="sam-api-apiauth-adddefaultauthorizertocorspreflight"></a>
Wenn die `Cors` Eigenschaften `DefaultAuthorizer` und gesetzt sind, `AddDefaultAuthorizerToCorsPreflight` führt die Einstellung dazu, dass der Standard-Authorizer zur `Options` Eigenschaft im OpenAPI-Abschnitt hinzugefügt wird.  
*Typ*: Boolesch  
*Required*: No  
*Standard*: Wahr  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.

 `ApiKeyRequired`   <a name="sam-api-apiauth-apikeyrequired"></a>
Wenn auf true gesetzt, ist ein API-Schlüssel für alle API-Ereignisse erforderlich. Weitere Informationen zu API-Schlüsseln finden Sie unter [Nutzungspläne mit API-Schlüsseln erstellen und verwenden](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html) im *API Gateway Developer Guide*.  
*Typ*: Boolesch  
*Required*: No  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.

 `Authorizers`   <a name="sam-api-apiauth-authorizers"></a>
Der Autorisierer, der zur Steuerung des Zugriffs auf Ihre API-Gateway-API verwendet wird.  
Weitere Informationen finden Sie unter [Kontrollieren Sie den API-Zugriff mit Ihrer AWS SAM Vorlage](serverless-controlling-access-to-apis.md).  
*Typ*: [CognitoAuthorizer](sam-property-api-cognitoauthorizer.md)\| \| [LambdaTokenAuthorizer](sam-property-api-lambdatokenauthorizer.md)\| [LambdaRequestAuthorizer](sam-property-api-lambdarequestauthorizer.md) AWS\_IAM  
*Required*: No  
*Standard*: Keiner  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.  
*Zusätzliche Hinweise*: SAM fügt die Authorizer zur OpenApi Definition einer API hinzu.

 `DefaultAuthorizer`   <a name="sam-api-apiauth-defaultauthorizer"></a>
Geben Sie einen Standardautorisierer für eine API-Gateway-API an, der standardmäßig für die Autorisierung von API-Aufrufen verwendet wird.  
Wenn die API EventSource für die mit dieser API verknüpfte Funktion für die Verwendung von IAM-Berechtigungen konfiguriert ist, muss diese Eigenschaft auf gesetzt werden`AWS_IAM`, da andernfalls ein Fehler auftritt.
*Typ:* Zeichenfolge  
*Required*: No  
*Standard*: Keiner  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.

 `InvokeRole`   <a name="sam-api-apiauth-invokerole"></a>
Legt die Integrationsanmeldedaten für alle Ressourcen und Methoden auf diesen Wert fest.  
`CALLER_CREDENTIALS`ordnet zu`arn:aws:iam::{{:<user>/}}`, wodurch die Anmeldeinformationen des Anrufers verwendet werden, um den Endpunkt aufzurufen.  
*Gültige Werte*:`CALLER_CREDENTIALS`,, `NONE` `IAMRoleArn`  
*Typ:* Zeichenfolge  
*Required*: No  
*Standardwert*: `CALLER_CREDENTIALS`  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.

 `ResourcePolicy`   <a name="sam-api-apiauth-resourcepolicy"></a>
Konfigurieren Sie die Ressourcenrichtlinie für alle Methoden und Pfade auf einer API.  
*Typ:* [ResourcePolicyStatement](sam-property-api-resourcepolicystatement.md)  
*Required*: No  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.  
*Zusätzliche Hinweise*: Diese Einstellung kann auch individuell `AWS::Serverless::Function` mit dem definiert werden[ApiFunctionAuth](sam-property-function-apifunctionauth.md). Dies ist für APIs with erforderlich`EndpointConfiguration: PRIVATE`.

 `UsagePlan`   <a name="sam-api-apiauth-usageplan"></a>
Konfiguriert einen mit dieser API verknüpften Nutzungsplan. Weitere Informationen zu Nutzungsplänen finden Sie unter [Nutzungspläne mit API-Schlüsseln erstellen und verwenden](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html) im *API Gateway Developer Guide*.  
Diese AWS SAM Eigenschaft generiert drei zusätzliche CloudFormation Ressourcen, wenn diese Eigenschaft festgelegt ist: an [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html), an und an [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html). Informationen zu diesem Szenario finden Sie unter[UsagePlan Eigenschaft ist spezifiziert](sam-specification-generated-resources-api.md#sam-specification-generated-resources-api-usage-plan). Allgemeine Informationen zu generierten CloudFormation Ressourcen finden Sie unter[Generierte CloudFormation Ressourcen für AWS SAM](sam-specification-generated-resources.md).  
*Typ:* [ApiUsagePlan](sam-property-api-apiusageplan.md)  
*Required*: No  
*CloudFormation Kompatibilität*: Diese Eigenschaft ist einzigartig für AWS SAM und hat kein CloudFormation Äquivalent.

## Beispiele
<a name="sam-property-api-apiauth--examples"></a>

### CognitoAuth
<a name="sam-property-api-apiauth--examples--cognitoauth"></a>

Beispiel für Cognito Auth

#### YAML
<a name="sam-property-api-apiauth--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers:
    MyCognitoAuth:
     UserPoolArn:
       Fn::GetAtt:
         - MyUserPool
         - Arn
     AuthType: "COGNITO_USER_POOLS"
  DefaultAuthorizer: MyCognitoAuth
  InvokeRole: CALLER_CREDENTIALS
  AddDefaultAuthorizerToCorsPreflight: false
  ApiKeyRequired: false
  ResourcePolicy:
    CustomStatements: [{
      "Effect": "Allow",
      "Principal": "*",
      "Action": "execute-api:Invoke",
      "Resource": "execute-api:/Prod/GET/pets",
      "Condition": {
          "IpAddress": {
              "aws:SourceIp": "1.2.3.4"
          }
        }
    }]
    IpRangeDenylist:
      - "10.20.30.40"
```

### AWS ICH BIN
<a name="sam-property-api-apiauth--examples--aws_iam"></a>

AWS IAM-Beispiel

#### YAML
<a name="sam-property-api-apiauth--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers: AWS_IAM
```