id
stringlengths 14
16
| text
stringlengths 1
2.43k
| source
stringlengths 99
229
|
---|---|---|
02d84e2eb8e0-0 | Lambda uses your function's permissions to create and manage network interfaces\. To connect to a VPC, your function's [execution role](lambda-intro-execution-role.md) must have the following permissions:
**Execution role permissions**
+ **ec2:CreateNetworkInterface**
+ **ec2:DescribeNetworkInterfaces**
+ **ec2:DeleteNetworkInterface**
These permissions are included in the AWS managed policy **AWSLambdaVPCAccessExecutionRole**\.
When you configure VPC connectivity, Lambda uses your permissions to verify network resources\. To configure a function to connect to a VPC, your AWS Identity and Access Management \(IAM\) user needs the following permissions:
**User permissions**
+ **ec2:DescribeSecurityGroups**
+ **ec2:DescribeSubnets**
+ **ec2:DescribeVpcs** | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
fd9b61da6032-0 | To connect a Lambda function to a VPC, you can use the following API operations:
+ [CreateFunction](API_CreateFunction.md)
+ [UpdateFunctionConfiguration](API_UpdateFunctionConfiguration.md)
To create a function and connect it to a VPC using the AWS Command Line Interface \(AWS CLI\), you can use the `create-function` command with the `vpc-config` option\. The following example creates a function with a connection to a VPC with two subnets and one security group\.
```
$ aws lambda create-function --function-name my-function \
--runtime nodejs12.x --handler index.js --zip-file fileb://function.zip \
--role arn:aws:iam::123456789012:role/lambda-role \
--vpc-config SubnetIds=subnet-071f712345678e7c8,subnet-07fd123456788a036,SecurityGroupIds=sg-085912345678492fb
```
To connect an existing function to a VPC, use the `update-function-configuration` command with the `vpc-config` option\.
```
$ aws lambda update-function-configuration --function-name my-function \ | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
fd9b61da6032-1 | ```
$ aws lambda update-function-configuration --function-name my-function \
--vpc-config SubnetIds=subnet-071f712345678e7c8,subnet-07fd123456788a036,SecurityGroupIds=sg-085912345678492fb
```
To disconnect your function from a VPC, update the function configuration with an empty list of subnets and security groups\.
```
$ aws lambda update-function-configuration --function-name my-function \
--vpc-config SubnetIds=[],SecurityGroupIds=[]
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
192bfe274287-0 | You can use Lambda\-specific condition keys for VPC settings to provide additional permission controls for your Lambda functions\. For example, you can require that all functions in your organization are connected to a VPC\. You can also specify the subnets and security groups that the function's users can and can't use\.
Lambda supports the following condition keys in IAM policies:
+ **lambda:VpcIds** – Allow or deny one or more VPCs\.
+ **lambda:SubnetIds** – Allow or deny one or more subnets\.
+ **lambda:SecurityGroupIds** – Allow or deny one or more security groups\.
The Lambda API operations [CreateFunction](API_CreateFunction.md) and [UpdateFunctionConfiguration](API_UpdateFunctionConfiguration.md) support these condition keys\. For more information about using condition keys in IAM policies, see [IAM JSON Policy Elements: Condition](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html) in the *IAM User Guide*\.
**Tip**
If your function already includes a VPC configuration from a previous API request, you can send an `UpdateFunctionConfiguration` request without the VPC configuration\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
1765f355df46-0 | The following examples demonstrate how to use condition keys for VPC settings\. After you create a policy statement with the desired restrictions, append the policy statement for the target IAM user or role\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
d765a7478841-0 | To ensure that all users deploy only VPC\-connected functions, you can deny function create and update operations that don't include a valid VPC ID\.
Note that VPC ID is not an input parameter to the `CreateFunction` or `UpdateFunctionConfiguration` request\. Lambda retrieves the VPC ID value based on the subnet and security group parameters\.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceVPCFunction",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Effect": "Deny",
"Resource": "*",
"Condition": {
"Null": {
"lambda:VpcIds": "true"
}
}
}
]
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
68012f906cc1-0 | To deny users access to specific VPCs, use `StringEquals` to check the value of the `lambda:VpcIds` condition\. The following example denies users access to `vpc-1` and `vpc-2`\.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceOutOfVPC",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Effect": "Deny",
"Resource": "*",
"Condition": {
"StringEquals": {
"lambda:VpcIds": ["vpc-1", "vpc-2"]
}
}
}
```
To deny users access to specific subnets, use `StringEquals` to check the value of the `lambda:SubnetIds` condition\. The following example denies users access to `subnet-1` and `subnet-2`\.
```
{
"Sid": "EnforceOutOfSubnet",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Effect": "Deny", | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
68012f906cc1-1 | "lambda:UpdateFunctionConfiguration"
],
"Effect": "Deny",
"Resource": "*",
"Condition": {
"ForAnyValue:StringEquals": {
"lambda:SubnetIds": ["subnet-1", "subnet-2"]
}
}
}
```
To deny users access to specific security groups, use `StringEquals` to check the value of the `lambda:SecurityGroupIds` condition\. The following example denies users access to `sg-1` and `sg-2`\.
```
{
"Sid": "EnforceOutOfSecurityGroups",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Effect": "Deny",
"Resource": "*",
"Condition": {
"ForAnyValue:StringEquals": {
"lambda:SecurityGroupIds": ["sg-1", "sg-2"]
}
}
}
]
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
6e6b8a56bb7c-0 | To allow users to access specific VPCs, use `StringEquals` to check the value of the `lambda:VpcIds` condition\. The following example allows users to access `vpc-1` and `vpc-2`\.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnforceStayInSpecificVpc",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Effect": "Allow",
"Resource": "*",
"Condition": {
"StringEquals": {
"lambda:VpcIds": ["vpc-1", "vpc-2"]
}
}
}
```
To allow users to access specific subnets, use `StringEquals` to check the value of the `lambda:SubnetIds` condition\. The following example allows users to access `subnet-1` and `subnet-2`\.
```
{
"Sid": "EnforceStayInSpecificSubnets",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Effect": "Allow", | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
6e6b8a56bb7c-1 | "lambda:UpdateFunctionConfiguration"
],
"Effect": "Allow",
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"lambda:SubnetIds": ["subnet-1", "subnet-2"]
}
}
}
```
To allow users to access specific security groups, use `StringEquals` to check the value of the `lambda:SecurityGroupIds` condition\. The following example allows users to access `sg-1` and `sg-2`\.
```
{
"Sid": "EnforceStayInSpecificSecurityGroup",
"Action": [
"lambda:CreateFunction",
"lambda:UpdateFunctionConfiguration"
],
"Effect": "Allow",
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"lambda:SecurityGroupIds": ["sg-1", "sg-2"]
}
}
}
]
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
a7e0d3493af8-0 | By default, Lambda runs your functions in a secure VPC with access to AWS services and the internet\. Lambda owns this VPC, which isn't connected to your account's [default VPC](https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html)\. When you connect a function to a VPC in your account, the function can't access the internet unless your VPC provides access\.
**Note**
Several AWS services offer [VPC endpoints](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-endpoints.html)\. You can use VPC endpoints to connect to AWS services from within a VPC without internet access\.
Internet access from a private subnet requires network address translation \(NAT\)\. To give your function access to the internet, route outbound traffic to a [NAT gateway](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html) in a public subnet\. The NAT gateway has a public IP address and can connect to the internet through the VPC's internet gateway\. For more information, see [How do I give internet access to my Lambda function in a VPC?](https://aws.amazon.com/premiumsupport/knowledge-center/internet-access-lambda-function/) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
328862d07f05-0 | You can use the following sample AWS CloudFormation templates to create VPC configurations to use with Lambda functions\. There are two templates available in this guide's GitHub repository:
+ [vpc\-private\.yaml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/templates/vpc-private.yaml) – A VPC with two private subnets and VPC endpoints for Amazon Simple Storage Service \(Amazon S3\) and Amazon DynamoDB\. Use this template to create a VPC for functions that don't need internet access\. This configuration supports use of Amazon S3 and DynamoDB with the AWS SDKs, and access to database resources in the same VPC over a local network connection\.
+ [vpc\-privatepublic\.yaml](https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/templates/vpc-privatepublic.yaml) – A VPC with two private subnets, VPC endpoints, a public subnet with a NAT gateway, and an internet gateway\. Internet\-bound traffic from functions in the private subnets is routed to the NAT gateway using a route table\.
To create a VPC using a template, on the AWS CloudFormation console [Stacks page](https://console.aws.amazon.com/cloudformation/home#/stacks), choose **Create stack**, and then follow the instructions in the **Create stack** wizard\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/configuration-vpc.md |
999d138b632a-0 | A deployment package is a ZIP archive that contains your compiled function code and dependencies\. You can upload the package directly to Lambda, or you can use an Amazon S3 bucket, and then upload it to Lambda\. If the deployment package is larger than 50 MB, you must use Amazon S3\.
AWS Lambda provides the following libraries for Java functions:
+ [com\.amazonaws:aws\-lambda\-java\-core](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-core) \(required\) – Defines handler method interfaces and the context object that the runtime passes to the handler\. If you define your own input types, this is the only library you need\.
+ [com\.amazonaws:aws\-lambda\-java\-events](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-events) – Input types for events from services that invoke Lambda functions\.
+ [com\.amazonaws:aws\-lambda\-java\-log4j2](https://github.com/aws/aws-lambda-java-libs/tree/master/aws-lambda-java-log4j2) – An appender library for Log4j 2 that you can use to add the request ID for the current invocation to your [function logs](java-logging.md)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
999d138b632a-1 | These libraries are available through [Maven central repository](https://search.maven.org/search?q=g:com.amazonaws)\. Add them to your build definition as follows\.
------ | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
226f2e2a8fe7-0 | ```
dependencies {
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:3.1.0'
runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.2.0'
}
```
------ | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
9161f8d9e7bd-0 | ```
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-log4j2</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
```
------
To create a deployment package, compile your function code and dependencies into a single ZIP or Java Archive \(JAR\) file\. For Gradle, [use the Zip build type](#java-package-gradle)\. For Maven, [use the Maven Shade plugin](#java-package-maven)\.
**Note** | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
9161f8d9e7bd-1 | **Note**
To keep your deployment package size small, package your function's dependencies in layers\. Layers let you manage your dependencies independently, can be used by multiple functions, and can be shared with other accounts\. For details, see [AWS Lambda layers](configuration-layers.md)\.
You can upload your deployment package by using the Lambda console, the Lambda API, or AWS SAM\.
**To upload a deployment package with the Lambda console**
1. Open the Lambda console [Functions page](https://console.aws.amazon.com/lambda/home#/functions)\.
1. Choose a function\.
1. Under **Function code**, choose **Upload**\.
1. Upload the deployment package\.
1. Choose **Save**\.
**Topics**
+ [Building a deployment package with Gradle](#java-package-gradle)
+ [Building a deployment package with Maven](#java-package-maven)
+ [Uploading a deployment package with the Lambda API](#java-package-cli)
+ [Uploading a deployment package with AWS SAM](#java-package-cloudformation) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
2f54fe3808f6-0 | Use the `Zip` build type to create a deployment package with your function's code and dependencies\.
**Example build\.gradle – Build task**
```
task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtimeClasspath
}
}
```
This build configuration produces a deployment package in the `build/distributions` folder\. The `compileJava` task compiles your function's classes\. The `processResources` tasks copies libraries from the build's classpath into a folder named `lib`\.
**Example build\.gradle – Dependencies**
```
dependencies {
implementation platform('software.amazon.awssdk:bom:2.10.73')
implementation 'software.amazon.awssdk:lambda'
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:3.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.apache.logging.log4j:log4j-api:2.13.0'
implementation 'org.apache.logging.log4j:log4j-core:2.13.0' | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
2f54fe3808f6-1 | implementation 'org.apache.logging.log4j:log4j-core:2.13.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.13.0'
runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.2.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
}
```
Lambda loads JAR files in Unicode alphabetical order\. If multiple JAR files in the `lib` folder contain the same class, the first one is used\. You can use the following shell script to identify duplicate classes\.
**Example test\-zip\.sh**
```
mkdir -p expanded
unzip path/to/my/function.zip -d expanded
find ./expanded/lib -name '*.jar' | xargs -n1 zipinfo -1 | grep '.*.class' | sort | uniq -c | sort
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
de352595e106-0 | To build a deployment package with Maven, use the [Maven Shade plugin](https://maven.apache.org/plugins/maven-shade-plugin/)\. The plugin creates a JAR file that contains the compiled function code and all of its dependencies\.
**Example pom\.xml – Plugin configuration**
```
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
```
To build the deployment package, use the `mvn package` command\.
```
[INFO] Scanning for projects...
[INFO] -----------------------< com.example:java-maven >----------------------- | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
de352595e106-1 | [INFO] Building java-maven-function 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
...
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ java-maven ---
[INFO] Building jar: target/java-maven-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:3.2.2:shade (default) @ java-maven ---
[INFO] Including com.amazonaws:aws-lambda-java-core:jar:1.2.1 in the shaded jar.
[INFO] Including com.amazonaws:aws-lambda-java-events:jar:3.1.0 in the shaded jar.
[INFO] Including joda-time:joda-time:jar:2.6 in the shaded jar.
[INFO] Including com.google.code.gson:gson:jar:2.8.6 in the shaded jar.
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing target/java-maven-1.0-SNAPSHOT.jar with target/java-maven-1.0-SNAPSHOT-shaded.jar | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
de352595e106-2 | [INFO] Replacing target/java-maven-1.0-SNAPSHOT.jar with target/java-maven-1.0-SNAPSHOT-shaded.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.321 s
[INFO] Finished at: 2020-03-03T09:07:19Z
[INFO] ------------------------------------------------------------------------
```
This command generates a JAR file in the `target` folder\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
de352595e106-3 | ```
This command generates a JAR file in the `target` folder\.
If you use the appender library \(`aws-lambda-java-log4j2`\), you must also configure a transformer for the Maven Shade plugin\. The transformer library combines versions of a cache file that appear in both the appender library and in Log4j\.
**Example pom\.xml – Plugin configuration with Log4j 2 appender**
```
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="com.github.edwgiz.maven_shade_plugin.log4j2_cache_transformer.PluginsCacheFileTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions> | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
de352595e106-4 | </transformer>
</transformers>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.github.edwgiz</groupId>
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
<version>2.13.0</version>
</dependency>
</dependencies>
</plugin>
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
6cb1f706263a-0 | To update a function's code with the AWS CLI or AWS SDK, use the [UpdateFunctionCode](API_UpdateFunctionCode.md) API operation\. For the AWS CLI, use the `update-function-code` command\. The following command uploads a deployment package named `my-function.zip` in the current directory\.
```
~/my-function$ aws lambda update-function-code --function-name my-function --zip-file fileb://my-function.zip
{
"FunctionName": "my-function",
"FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function",
"Runtime": "java8",
"Role": "arn:aws:iam::123456789012:role/lambda-role",
"Handler": "example.Handler",
"CodeSha256": "Qf0hMc1I2di6YFMi9aXm3JtGTmcDbjniEuiYonYptAk=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "Active"
},
"RevisionId": "983ed1e3-ca8e-434b-8dc1-7d72ebadd83d",
...
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
6cb1f706263a-1 | ...
}
```
If your deployment package is larger than 50 MB, you can't upload it directly\. Upload it to an Amazon S3 bucket and point Lambda to the object\. The following example commands upload a deployment package to a bucket named `my-bucket` and use it to update a function's code\.
```
~/my-function$ aws s3 cp my-function.zip s3://my-bucket
upload: my-function.zip to s3://my-bucket/my-function
~/my-function$ aws lambda update-function-code --function-name my-function \
--s3-bucket my-bucket --s3-key my-function.zip
{
"FunctionName": "my-function",
"FunctionArn": "arn:aws:lambda:us-east-2:123456789012:function:my-function",
"Runtime": "java8",
"Role": "arn:aws:iam::123456789012:role/lambda-role",
"Handler": "example.Handler",
"CodeSha256": "Qf0hMc1I2di6YFMi9aXm3JtGTmcDbjniEuiYonYptAk=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "Active" | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
6cb1f706263a-2 | "Version": "$LATEST",
"TracingConfig": {
"Mode": "Active"
},
"RevisionId": "983ed1e3-ca8e-434b-8dc1-7d72ebadd83d",
...
}
```
You can use this method to upload function packages up to 250 MB \(decompressed\)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
46e779ce89e4-0 | You can use the AWS Serverless Application Model to automate deployments of your function code, configuration, and dependencies\. AWS SAM is an extension of AWS CloudFormation that provides a simplified syntax for defining serverless applications\. The following example template defines a function with a deployment package in the `build/distributions` directory that Gradle uses\.
**Example template\.yml**
```
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Lambda application that calls the Lambda API.
Resources:
function:
Type: [AWS::Serverless::Function](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html)
Properties:
CodeUri: build/distributions/java-basic.zip
Handler: example.Handler
Runtime: java8
Description: Java function
MemorySize: 512
Timeout: 10 | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
baefe3d373da-0 | Policies:
- AWSLambdaBasicExecutionRole
- AWSLambdaReadOnlyAccess
- AWSXrayWriteOnlyAccess
- AWSLambdaVPCAccessExecutionRole
Tracing: Active
```
To create the function, use the `package` and `deploy` commands\. These commands are customizations to the AWS CLI\. They wrap other commands to upload the deployment package to Amazon S3, rewrite the template with the object URI, and update the function's code\.
The following example script runs a Gradle build and uploads the deployment package that it creates\. It creates an AWS CloudFormation stack the first time you run it\. If the stack already exists, the script updates it\.
**Example deploy\.sh**
```
#!/bin/bash
set -eo pipefail
aws cloudformation package --template-file template.yml --s3-bucket MY_BUCKET --output-template-file out.yml
aws cloudformation deploy --template-file out.yml --stack-name java-basic --capabilities CAPABILITY_NAMED_IAM
```
For a complete working example, see the following sample applications\.
**Sample Lambda applications in Java** | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
baefe3d373da-1 | ```
For a complete working example, see the following sample applications\.
**Sample Lambda applications in Java**
+ [blank\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/blank-java) – A Java function that shows the use of Lambda's Java libraries, logging, environment variables, layers, AWS X\-Ray tracing, unit tests, and the AWS SDK\.
+ [java\-basic](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-basic) – A minimal Java function with unit tests and variable logging configuration\.
+ [java\-events](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-events) – A minimal Java function that uses the [aws\-lambda\-java\-events](#java-package) library with event types that don't require the AWS SDK as a dependency, such as Amazon API Gateway\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
baefe3d373da-2 | + [java\-events\-v1sdk](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/java-events-v1sdk) – A Java function that uses the [aws\-lambda\-java\-events](#java-package) library with event types that require the AWS SDK as a dependency \(Amazon Simple Storage Service, Amazon DynamoDB, and Amazon Kinesis\)\.
+ [s3\-java](https://github.com/awsdocs/aws-lambda-developer-guide/tree/master/sample-apps/s3-java) – A Java function that processes notification events from Amazon S3 and uses the Java Class Library \(JCL\) to create thumbnails from uploaded image files\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/java-package.md |
3bda297a655e-0 | Returns a list of Lambda functions, with the version\-specific configuration of each\. Lambda returns up to 50 functions per call\.
Set `FunctionVersion` to `ALL` to include all published versions of each function in addition to the unpublished version\. To get more information about a function or version, use [GetFunction](API_GetFunction.md)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
65d35a47e227-0 | ```
GET /2015-03-31/functions/?FunctionVersion=FunctionVersion&Marker=Marker&MasterRegion=MasterRegion&MaxItems=MaxItems HTTP/1.1
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
89e1942eac99-0 | The request uses the following URI parameters\.
** [FunctionVersion](#API_ListFunctions_RequestSyntax) ** <a name="SSS-ListFunctions-request-FunctionVersion"></a>
Set to `ALL` to include entries for all published versions of each function\.
Valid Values:` ALL`
** [Marker](#API_ListFunctions_RequestSyntax) ** <a name="SSS-ListFunctions-request-Marker"></a>
Specify the pagination token that's returned by a previous request to retrieve the next page of results\.
** [MasterRegion](#API_ListFunctions_RequestSyntax) ** <a name="SSS-ListFunctions-request-MasterRegion"></a>
For Lambda@Edge functions, the AWS Region of the master function\. For example, `us-east-1` filters the list of functions to only include Lambda@Edge functions replicated from a master function in US East \(N\. Virginia\)\. If specified, you must set `FunctionVersion` to `ALL`\.
Pattern: `ALL|[a-z]{2}(-gov)?-[a-z]+-\d{1}`
** [MaxItems](#API_ListFunctions_RequestSyntax) ** <a name="SSS-ListFunctions-request-MaxItems"></a>
The maximum number of functions to return\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
89e1942eac99-1 | The maximum number of functions to return\.
Valid Range: Minimum value of 1\. Maximum value of 10000\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
acaf64318ec7-0 | The request does not have a request body\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
d58a5ddb8262-0 | ```
HTTP/1.1 200
Content-type: application/json
{
"Functions": [
{
"CodeSha256": "string",
"CodeSize": number,
"DeadLetterConfig": {
"TargetArn": "string"
},
"Description": "string",
"Environment": {
"Error": {
"ErrorCode": "string",
"Message": "string"
},
"Variables": {
"string" : "string"
}
},
"FileSystemConfigs": [
{
"Arn": "string",
"LocalMountPath": "string"
}
],
"FunctionArn": "string",
"FunctionName": "string",
"Handler": "string",
"KMSKeyArn": "string",
"LastModified": "string",
"LastUpdateStatus": "string",
"LastUpdateStatusReason": "string",
"LastUpdateStatusReasonCode": "string",
"Layers": [
{ | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
d58a5ddb8262-1 | "LastUpdateStatusReasonCode": "string",
"Layers": [
{
"Arn": "string",
"CodeSize": number
}
],
"MasterArn": "string",
"MemorySize": number,
"RevisionId": "string",
"Role": "string",
"Runtime": "string",
"State": "string",
"StateReason": "string",
"StateReasonCode": "string",
"Timeout": number,
"TracingConfig": {
"Mode": "string"
},
"Version": "string",
"VpcConfig": {
"SecurityGroupIds": [ "string" ],
"SubnetIds": [ "string" ],
"VpcId": "string"
}
}
],
"NextMarker": "string"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
65567feffbd8-0 | If the action is successful, the service sends back an HTTP 200 response\.
The following data is returned in JSON format by the service\.
** [Functions](#API_ListFunctions_ResponseSyntax) ** <a name="SSS-ListFunctions-response-Functions"></a>
A list of Lambda functions\.
Type: Array of [FunctionConfiguration](API_FunctionConfiguration.md) objects
** [NextMarker](#API_ListFunctions_ResponseSyntax) ** <a name="SSS-ListFunctions-response-NextMarker"></a>
The pagination token that's included if more results are available\.
Type: String | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
d8b9f8d59fa2-0 | **InvalidParameterValueException**
One of the parameters in the request is invalid\.
HTTP Status Code: 400
**ServiceException**
The AWS Lambda service encountered an internal error\.
HTTP Status Code: 500
**TooManyRequestsException**
The request throughput limit was exceeded\.
HTTP Status Code: 429 | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
3fecb64a9ec5-0 | For more information about using this API in one of the language\-specific AWS SDKs, see the following:
+ [AWS Command Line Interface](https://docs.aws.amazon.com/goto/aws-cli/lambda-2015-03-31/ListFunctions)
+ [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/ListFunctions)
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/ListFunctions)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/ListFunctions)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/ListFunctions)
+ [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/ListFunctions)
+ [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/ListFunctions) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
3fecb64a9ec5-1 | + [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/ListFunctions)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/ListFunctions) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_ListFunctions.md |
143b99ea5aa5-0 | Grants an AWS service or another account permission to use a function\. You can apply the policy at the function level, or specify a qualifier to restrict access to a single version or alias\. If you use a qualifier, the invoker must use the full Amazon Resource Name \(ARN\) of that version or alias to invoke the function\.
To grant permission to another account, specify the account ID as the `Principal`\. For AWS services, the principal is a domain\-style identifier defined by the service, like `s3.amazonaws.com` or `sns.amazonaws.com`\. For AWS services, you can also specify the ARN of the associated resource as the `SourceArn`\. If you grant permission to a service principal without specifying the source, other accounts could potentially configure resources in their account to invoke your Lambda function\.
This action adds a statement to a resource\-based permissions policy for the function\. For more information about function policies, see [Lambda Function Policies](https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html)\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
2f0fe8f068fa-0 | ```
POST /2015-03-31/functions/FunctionName/policy?Qualifier=Qualifier HTTP/1.1
Content-type: application/json
{
"Action": "string",
"EventSourceToken": "string",
"Principal": "string",
"RevisionId": "string",
"SourceAccount": "string",
"SourceArn": "string",
"StatementId": "string"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
2c11725d9306-0 | The request uses the following URI parameters\.
** [FunctionName](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-FunctionName"></a>
The name of the Lambda function, version, or alias\.
**Name formats**
+ **Function name** \- `my-function` \(name\-only\), `my-function:v1` \(with alias\)\.
+ **Function ARN** \- `arn:aws:lambda:us-west-2:123456789012:function:my-function`\.
+ **Partial ARN** \- `123456789012:function:my-function`\.
You can append a version number or alias to any of the formats\. The length constraint applies only to the full ARN\. If you specify only the function name, it is limited to 64 characters in length\.
Length Constraints: Minimum length of 1\. Maximum length of 140\.
Pattern: `(arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?`
Required: Yes | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
2c11725d9306-1 | Required: Yes
** [Qualifier](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-Qualifier"></a>
Specify a version or alias to add permissions to a published version of the function\.
Length Constraints: Minimum length of 1\. Maximum length of 128\.
Pattern: `(|[a-zA-Z0-9$_-]+)` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
656a83990797-0 | The request accepts the following data in JSON format\.
** [Action](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-Action"></a>
The action that the principal can use on the function\. For example, `lambda:InvokeFunction` or `lambda:GetFunction`\.
Type: String
Pattern: `(lambda:[*]|lambda:[a-zA-Z]+|[*])`
Required: Yes
** [EventSourceToken](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-EventSourceToken"></a>
For Alexa Smart Home functions, a token that must be supplied by the invoker\.
Type: String
Length Constraints: Minimum length of 0\. Maximum length of 256\.
Pattern: `[a-zA-Z0-9._\-]+`
Required: No
** [Principal](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-Principal"></a>
The AWS service or account that invokes the function\. If you specify a service, use `SourceArn` or `SourceAccount` to limit who can invoke the function through that service\.
Type: String
Pattern: `.*`
Required: Yes | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
656a83990797-1 | Type: String
Pattern: `.*`
Required: Yes
** [RevisionId](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-RevisionId"></a>
Only update the policy if the revision ID matches the ID that's specified\. Use this option to avoid modifying a policy that has changed since you last read it\.
Type: String
Required: No
** [SourceAccount](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-SourceAccount"></a>
For Amazon S3, the ID of the account that owns the resource\. Use this together with `SourceArn` to ensure that the resource is owned by the specified account\. It is possible for an Amazon S3 bucket to be deleted by its owner and recreated by another account\.
Type: String
Pattern: `\d{12}`
Required: No
** [SourceArn](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-SourceArn"></a>
For AWS services, the ARN of the AWS resource that invokes the function\. For example, an Amazon S3 bucket or Amazon SNS topic\.
Type: String | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
656a83990797-2 | Type: String
Pattern: `arn:(aws[a-zA-Z0-9-]*):([a-zA-Z0-9\-])+:([a-z]{2}(-gov)?-[a-z]+-\d{1})?:(\d{12})?:(.*)`
Required: No
** [StatementId](#API_AddPermission_RequestSyntax) ** <a name="SSS-AddPermission-request-StatementId"></a>
A statement identifier that differentiates the statement from others in the same policy\.
Type: String
Length Constraints: Minimum length of 1\. Maximum length of 100\.
Pattern: `([a-zA-Z0-9-_]+)`
Required: Yes | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
b70b8e7c5b3c-0 | ```
HTTP/1.1 201
Content-type: application/json
{
"Statement": "string"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
2a96e4e9bf44-0 | If the action is successful, the service sends back an HTTP 201 response\.
The following data is returned in JSON format by the service\.
** [Statement](#API_AddPermission_ResponseSyntax) ** <a name="SSS-AddPermission-response-Statement"></a>
The permission statement that's added to the function policy\.
Type: String | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
8ae9f0db223a-0 | **InvalidParameterValueException**
One of the parameters in the request is invalid\.
HTTP Status Code: 400
**PolicyLengthExceededException**
The permissions policy for the resource is too large\. [Learn more](https://docs.aws.amazon.com/lambda/latest/dg/limits.html)
HTTP Status Code: 400
**PreconditionFailedException**
The RevisionId provided does not match the latest RevisionId for the Lambda function or alias\. Call the `GetFunction` or the `GetAlias` API to retrieve the latest RevisionId for your resource\.
HTTP Status Code: 412
**ResourceConflictException**
The resource already exists, or another operation is in progress\.
HTTP Status Code: 409
**ResourceNotFoundException**
The resource specified in the request does not exist\.
HTTP Status Code: 404
**ServiceException**
The AWS Lambda service encountered an internal error\.
HTTP Status Code: 500
**TooManyRequestsException**
The request throughput limit was exceeded\.
HTTP Status Code: 429 | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
17c3469b8c78-0 | For more information about using this API in one of the language\-specific AWS SDKs, see the following:
+ [AWS Command Line Interface](https://docs.aws.amazon.com/goto/aws-cli/lambda-2015-03-31/AddPermission)
+ [AWS SDK for \.NET](https://docs.aws.amazon.com/goto/DotNetSDKV3/lambda-2015-03-31/AddPermission)
+ [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/lambda-2015-03-31/AddPermission)
+ [AWS SDK for Go](https://docs.aws.amazon.com/goto/SdkForGoV1/lambda-2015-03-31/AddPermission)
+ [AWS SDK for Java](https://docs.aws.amazon.com/goto/SdkForJava/lambda-2015-03-31/AddPermission)
+ [AWS SDK for JavaScript](https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/AddPermission)
+ [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/lambda-2015-03-31/AddPermission) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
17c3469b8c78-1 | + [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/lambda-2015-03-31/AddPermission)
+ [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/lambda-2015-03-31/AddPermission) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-lambda-developer-guide/doc_source/API_AddPermission.md |
6aaca54c8afa-0 | The following Java sample shows how to use the [DescribeCertificateAuthority](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_DescribeCertificateAuthority.html) operation\.
The operation lists information about your private certificate authority \(CA\)\. You must specify the ARN \(Amazon Resource Name\) of the private CA\. The output contains the status of your CA\. This can be any of the following:
+ `CREATING` – ACM Private CA is creating your private certificate authority\.
+ `PENDING_CERTIFICATE` – The certificate is pending\. You must use your on\-premises root or subordinate CA to sign your private CA CSR and then import it into PCA\.
+ `ACTIVE` – Your private CA is active\.
+ `DISABLED` – Your private CA has been disabled\.
+ `EXPIRED` – Your private CA certificate has expired\.
+ `FAILED` – Your private CA cannot be created\.
+ `DELETED` – Your private CA is within the restoration period, after which it will be permanently deleted\.
```
package com.amazonaws.samples;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-DescribeCertificateAuthority.md |
6aaca54c8afa-1 | import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.services.acmpca.AWSACMPCA;
import com.amazonaws.services.acmpca.AWSACMPCAClientBuilder;
import com.amazonaws.services.acmpca.model.CertificateAuthority;
import com.amazonaws.services.acmpca.model.DescribeCertificateAuthorityRequest;
import com.amazonaws.services.acmpca.model.DescribeCertificateAuthorityResult;
import com.amazonaws.AmazonClientException;
import com.amazonaws.services.acmpca.model.ResourceNotFoundException;
import com.amazonaws.services.acmpca.model.InvalidArnException;
public class DescribeCertificateAuthority {
public static void main(String[] args) throws Exception {
// Retrieve your credentials from the C:\Users\name\.aws\credentials file
// in Windows or the .aws/credentials file in Linux.
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider("default").getCredentials();
} catch (Exception e) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-DescribeCertificateAuthority.md |
6aaca54c8afa-2 | credentials = new ProfileCredentialsProvider("default").getCredentials();
} catch (Exception e) {
throw new AmazonClientException("Cannot load your credentials from disk", e);
}
// Define the endpoint for your sample.
String endpointRegion = "region"; // Substitute your region here, e.g. "us-west-2"
String endpointProtocol = "https://acm-pca." + endpointRegion + ".amazonaws.com/";
EndpointConfiguration endpoint =
new AwsClientBuilder.EndpointConfiguration(endpointProtocol, endpointRegion);
// Create a client that you can use to make requests.
AWSACMPCA client = AWSACMPCAClientBuilder.standard()
.withEndpointConfiguration(endpoint)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
// Create a request object
DescribeCertificateAuthorityRequest req = new DescribeCertificateAuthorityRequest();
// Set the certificate authority ARN.
req.withCertificateAuthorityArn("arn:aws:acm-pca:region:account:"+ | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-DescribeCertificateAuthority.md |
6aaca54c8afa-3 | req.withCertificateAuthorityArn("arn:aws:acm-pca:region:account:"+
"certificate-authority/12345678-1234-1234-1234-123456789012");
// Create a result object.
DescribeCertificateAuthorityResult result = null;
try {
result = client.describeCertificateAuthority(req);
} catch (ResourceNotFoundException ex) {
throw ex;
} catch (InvalidArnException ex) {
throw ex;
}
// Retrieve and display information about the CA.
CertificateAuthority PCA = result.getCertificateAuthority();
String strPCA = PCA.toString();
System.out.println(strPCA);
}
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-DescribeCertificateAuthority.md |
15aa062527c1-0 | Best practices are recommendations that can help you use ACM Private CA effectively\. The following best practices are based on real\-world experience from current AWS Certificate Manager and ACM Private CA customers\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
fbc171de0347-0 | AWS recommends documenting all of your policies and practices for operating your CA\. This might include:
+ Reasoning for your decisions about CA structure
+ A diagram showing your CAs and their relationships
+ Policies on CA validity periods
+ Planning for CA succession
+ Policies on path length
+ Catalog of permissions
+ Description of administrative control structures
+ Security
You can capture this information in two documents, known as Certification Policy \(CP\) and Certification Practices Statement \(CPS\)\. Refer to [RFC 3647](https://www.ietf.org/rfc/rfc3647.txt) for a framework for capturing important information about your CA operations\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
751f28c7d17d-0 | A root CA should in general only be used to issue certificates for intermediate CAs\. This allows the root CA to be stored out of harm's way while the intermediate CAs perform the daily task of issuing end\-entity certificates\.
However, if your organization's current practice is to issue end\-entity certificates directly from a root CA, ACM Private CA can support this workflow while improving security and operational controls\. Issuing end\-entity certificates in this scenario requires an IAM permissions policy that permits your root CA to use an end\-entity certificate template\. For information about IAM policies, see [Identity and Access Management for AWS Certificate Manager Private Certificate Authority](security-iam.md)\.
**Note**
This configuration imposes limitations that may result in operational challenges\. For example, if your root CA is compromised or lost, you must create a new root CA and distribute it to all of the clients in your environment\. Until this recovery process is complete, you will not be able to issue new certificates\. Issuing certificates directly from a root CA also prevents you from restricting access and limiting the number of certificates issued from your root, which are both considered best practices for managing a root CA\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
29152a0d8311-0 | Creating a root CA and subordinate CA in two different AWS accounts is a recommended best practice\. Doing so can provide you with additional protection and access controls for your root CA\. You can do so by exporting the CSR from the subordinate CA in one account, and signing it with a root CA in a different account\. The benefit of this approach is that you can separate control of your CAs by account\. The disadvantage is that | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
29152a0d8311-1 | your CAs by account\. The disadvantage is that you cannot use the AWS management console wizard to simplify the process of signing the CA certificate of a subordinate CA from your Root CA\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
dedfdefd7e1d-0 | The CA administrator role should be separate from users who need only to issue end\-entity certificates\. If your CA administrator and certificate issuer reside in the same AWS account, you can limit issuer permissions by creating an IAM user specifically for that purpose\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
d7c963d6a6c5-0 | Turn on CloudTrail logging before you create and start operating a private CA\. With CloudTrail you can retrieve a history of AWS API calls for your account to monitor your AWS deployments\. This history includes API calls made from the AWS Management Console, the AWS SDKs, the AWS Command Line Interface, and higher\-level AWS services\. You can also identify which users and accounts called the PCA API operations, the source IP address the calls were | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
d7c963d6a6c5-1 | operations, the source IP address the calls were made from, and when the calls occurred\. You can integrate CloudTrail into applications using the API, automate trail creation for your organization, check the status of your trails, and control how administrators turn CloudTrail logging on and off\. For more information, see [Creating a Trail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)\. Go to [Using CloudTrail](PcaCtIntro.md) to see example trails for ACM Private CA | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
d7c963d6a6c5-2 | to see example trails for ACM Private CA operations\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
bd46f5173d36-0 | It is a best practice to periodically update the private key for your private CA\. You can update a key by importing a new CA certificate, or you can replace the private CA with a new CA\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
b7a521b11b74-0 | You can permanently delete a private CA\. You might want to do so if you no longer need the CA or if you want to replace it with a CA that has a newer private key\. To safely delete a CA, we recommend that you follow the process outlined in [Deleting Your Private CA](PCADeleteCA.md)\.
**Note**
AWS bills you for a CA until it has been deleted\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-best-practices.md |
ac59505e443b-0 | CA certificates have a fixed lifetime, or validity period\. When a CA certificate expires, all of the certificates issued directly or indirectly by subordinate CAs below it in the CA hierarchy become invalid\. You can avoid CA certificate expiration by planning in advance\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
d5f879384383-0 | The validity period of an X\.509 certificate is a required basic certificate field\. It determines the time\-range during which the issuing CA certifies that the certificate can be trusted, barring revocation\. \(A root certificate, being self\-signed, certifies its own validity period\.\)
ACM Private CA and AWS Certificate Manager assist with the configuration of certificate validity periods subject to the following constraints:
+ A certificate managed by ACM Private CA must have a validity period shorter than or equal to the validity period of the CA that issued it\. In other words, child CAs and end\-entity certificates cannot outlive their parent certificates\. Attempting to use the `IssueCertificate` API to issue a CA certificate with a validity period greater than or equal to the parent's CA fails\.
+ Certificates issued and managed by AWS Certificate Manager \(those for which ACM generates the private key\) have a validity period of 13 months \(395 days\)\. ACM manages the renewal process for these certificates\. If you use ACM Private CA to issue certificates directly, you can choose any validity period\.
The following diagram shows a typical configuration of nested validity periods\. The root certificate is the most long\-lived; end\-entity certificates are relatively short\-lived; and subordinate CAs range between these extremes\.
![\[Subordinate and validity periods must fall within the validity periods of their parents.\]](http://docs.aws.amazon.com/acm-pca/latest/userguide/images/validity.png) | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
d5f879384383-1 | When you plan your CA hierarchy, determine the optimal lifetime for your CA certificates\. Work backwards from the desired lifetime of the end\-entity certificates that you want to issue\.
**End\-entity certificates**
End\-entity certificates should have a validity period appropriate to the use case\. A short lifetime minimizes the exposure of a certificate in the event that its private key is lost or stolen\. However, short lifetimes mean frequent renewals\. Failure to renew an expiring certificate can result in downtime\.
The distributed use of end\-entity certificates can also present logistical problems if there is a security breach\. Your planning should account for renewal and distribution certificates, revocation of compromised certificates, and how quickly revocations propagate to clients that rely on the certificates\.
The default validity period for an end\-entity certificate issued through ACM is 13 months \(395 days\)\. In ACM Private CA, you can use the `IssueCertificate` API to apply any validity period so long as it is less than that of the issuing CA\.
**Subordinate CA Certificates** | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
d5f879384383-2 | **Subordinate CA Certificates**
Subordinate CA certificates should have significantly longer validity periods than the certificates they issue\. A good range for a CA certificate's validity is two to five times the period of any child CA certificate or end\-entity certificate it issues\. For example, assume you have a two\-level CA hierarchy \(root CA and one subordinate CA\)\. If you want to issue end\-entity certificates with a one\-year lifetime, you could configure the subordinate issuing CA lifetime to be three years\. This is the default validity period for a subordinate CA certificate in ACM Private CA\. Subordinate CA certificates can be changed without replacing the root CA certificate\.
**Root Certificates**
Changes to a root CA certificate affect the entire PKI \(public key infrastructure\) and require you to update all the dependent client operating system and browser trust stores\. To minimize operational impact, you should choose a long validity period for the root certificate\. The ACM Private CA default for root certificates is ten years\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
4069afebb538-0 | You have two ways to manage CA succession: Replace the old CA, or reissue the CA with a new validity period\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
7f6271abb986-0 | To replace an old CA, you create a new CA and chain it to the same parent CA\. Afterward, you issue certificates from the new CA\.
Certificates issued from the new CA have a new CA chain\. Once the new CA is established, you can disable the old CA to prevent it from issuing new certificates\. While disabled, the old CA supports revocation for old certificates issued from the CA, and it continues to generate certificate revocation lists \(CRLs\)\. When the last certificate issued from the old CA expires, you can delete the old CA\. You can generate an audit report for all of the certificates issued from the CA to confirm that all of the certificates issued have expired\. If the old CA has subordinate CAs, you must also replace them, because subordinate CAs expire at the same time or before their parent CA\. Start by replacing the highest CA in the hierarchy that needs to be replaced\. Then create new replacement subordinate CAs at each subsequent lower level\.
AWS recommends that you include a CA generation identifier in the names of CAs as needed\. For example, assume that you name the first generation CA “Corporate Root CA\." When you create the second generation CA, name it “Corporate Root CA G2\." This simple naming convention can help avoid confusion when both CAs are unexpired\.
This method of CA succession is preferred because it rotates the private key of the CA\. Rotating the private key is a best practice for CA keys\. The frequency of rotation should be proportional to the frequency of key use: CAs that issue more certificates should be rotated more frequently\.
**Note** | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
7f6271abb986-1 | **Note**
Private certificates issued through ACM cannot be renewed if you replace the CA\. If you use ACM for issuance and renewal, you must re\-issue the CA certificate to extend the lifetime of the CA\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
6033ec933c00-0 | When you revoke a CA certificate, you effectively revoke all of the certificates issued by the CA\. Revocation information is distributed to clients via the CRL\. Clients will stop trusting certificates issued by the CA as soon as they receive the updated CRL\. You should revoke a CA certificate only if you want to effectively revoke all of the end\-entity and CA certificates\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/ca-lifecycle.md |
7726b7b20b70-0 | The following Java sample shows how to use the [RevokeCertificate](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_RevokeCertificate.html) operation\.
This operation revokes a certificate that you issued by calling the [IssueCertificate](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_IssueCertificate.html) operation\. If you enabled a certificate revocation list \(CRL\) when you created or updated your private CA, information about the revoked certificates is included in the CRL\. ACM Private CA writes the CRL to an Amazon S3 bucket that you specify\. For more information, see the [CrlConfiguration](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_CrlConfiguration.html) structure\.
```
package com.amazonaws.samples;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSStaticCredentialsProvider; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-RevokeCertificate.md |
7726b7b20b70-1 | import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.services.acmpca.AWSACMPCA;
import com.amazonaws.services.acmpca.AWSACMPCAClientBuilder;
import com.amazonaws.services.acmpca.model.RevokeCertificateRequest;
import com.amazonaws.services.acmpca.model.RevocationReason;
import com.amazonaws.services.acmpca.model.ResourceNotFoundException;
import com.amazonaws.services.acmpca.model.InvalidStateException;
import com.amazonaws.services.acmpca.model.InvalidArnException;
import com.amazonaws.services.acmpca.model.RequestFailedException;
import com.amazonaws.services.acmpca.model.RequestAlreadyProcessedException;
import com.amazonaws.services.acmpca.model.RequestInProgressException;
public class RevokeCertificate {
public static void main(String[] args) throws Exception {
// Retrieve your credentials from the C:\Users\name\.aws\credentials file
// in Windows or the .aws/credentials file in Linux.
AWSCredentials credentials = null;
try { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-RevokeCertificate.md |
7726b7b20b70-2 | // in Windows or the .aws/credentials file in Linux.
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider("default").getCredentials();
} catch (Exception e) {
throw new AmazonClientException("Cannot load your credentials from disk", e);
}
// Define the endpoint for your sample.
String endpointRegion = "region"; // Substitute your region here, e.g. "us-west-2"
String endpointProtocol = "https://acm-pca." + endpointRegion + ".amazonaws.com/";
EndpointConfiguration endpoint =
new AwsClientBuilder.EndpointConfiguration(endpointProtocol, endpointRegion);
// Create a client that you can use to make requests.
AWSACMPCA client = AWSACMPCAClientBuilder.standard()
.withEndpointConfiguration(endpoint)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
// Create a request object.
RevokeCertificateRequest req = new RevokeCertificateRequest();
// Set the certificate authority ARN. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-RevokeCertificate.md |
7726b7b20b70-3 | RevokeCertificateRequest req = new RevokeCertificateRequest();
// Set the certificate authority ARN.
req.setCertificateAuthorityArn("arn:aws:acm-pca:region:account:" +
"certificate-authority/12345678-1234-1234-1234-123456789012");
// Set the certificate serial number.
req.setCertificateSerial("79:3f:0d:5b:6a:04:12:5e:2c:9c:fb:52:37:35:98:fe");
// Set the RevocationReason.
req.withRevocationReason(RevocationReason.<<KEY_COMPROMISE>>);
// Revoke the certificate.
try {
client.revokeCertificate(req);
} catch (InvalidArnException ex) {
throw ex;
} catch (InvalidStateException ex) {
throw ex;
} catch (ResourceNotFoundException ex) {
throw ex;
} catch (RequestAlreadyProcessedException ex) {
throw ex;
} catch (RequestInProgressException ex) {
throw ex;
} catch (RequestFailedException ex) {
throw ex;
} | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-RevokeCertificate.md |
7726b7b20b70-4 | throw ex;
} catch (RequestFailedException ex) {
throw ex;
}
}
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-RevokeCertificate.md |
ede3a389afa7-0 | The following CloudTrail example shows the results of a call to the [UpdateCertificateAuthority](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_UpdateCertificateAuthority.html) operation\.
```
{
"eventVersion":"1.05",
"userIdentity":{
"type":"IAMUser",
"principalId":"account",
"arn":"arn:aws:iam::account:user/name",
"accountId":"account",
"accessKeyId":"Key_ID"
},
"eventTime":"2018-01-26T22:08:59Z",
"eventSource":"acm-pca.amazonaws.com",
"eventName":"UpdateCertificateAuthority",
"awsRegion":"us-east-1",
"sourceIPAddress":"xx.xx.xx.xx",
"userAgent":"aws-cli/1.14.28 Python/2.7.9 Windows/8 botocore/1.8.32",
"requestParameters":{ | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/CT-UpdateCA.md |
ede3a389afa7-1 | "requestParameters":{
"certificateAuthorityArn":"arn:aws:acm-pca:region:account:certificate-authority/09517d62-4f11-4bf8-a2c9-9e863792b675",
"revocationConfiguration":{
"crlConfiguration":{
"enabled":true,
"expirationInDays":3650,
"customCname":"your-custom-name",
s3BucketName:"your-bucket-name"
}
},
"status":"DISABLED"
},
"responseElements":null,
"requestID":"24f849f9-9966-4f13-8ff6-3e2e84b327fc",
"eventID":"16c78ea0-e3d7-4817-9bb0-0b997789678f",
"eventType":"AwsApiCall",
"recipientAccountId":"account"
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/CT-UpdateCA.md |
81a4721722df-0 | After you create your private CA, you must retrieve the CSR and submit it to an intermediate or root CA in your X\.509 infrastructure\. Your CA uses the CSR to create your private CA certificate and then signs the certificate before returning it to you\.
Unfortunately, it is not possible to provide specific advice on problems related to creating and signing your private CA certificate\. The details of your X\.509 infrastructure and the CA hierarchy within it are beyond the scope of this documentation\. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/PcaTsSignCsr.md |
fba22601609b-0 | This Java sample shows how to activate a root CA using the following ACM Private CA API actions:
+ [CreateCertificateAuthority](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_CreateCertificateAuthority.html)
+ [GetCertificateAuthorityCsr](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_GetCertificateAuthorityCsr.html)
+ [IssueCertificate](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_IssueCertificate.html)
+ [GetCertificate](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_GetCertificate.html)
+ [ImportCertificateAuthorityCertificate](https://docs.aws.amazon.com/acm-pca/latest/APIReference/API_ImportCertificateAuthorityCertificate.html)
```
package com.amazonaws.samples;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-1 | import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.samples.GetCertificateAuthorityCertificate;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.services.acmpca.AWSACMPCA;
import com.amazonaws.services.acmpca.AWSACMPCAClientBuilder;
import com.amazonaws.services.acmpca.model.ASN1Subject;
import com.amazonaws.services.acmpca.model.CertificateAuthorityConfiguration;
import com.amazonaws.services.acmpca.model.CertificateAuthorityType;
import com.amazonaws.services.acmpca.model.CreateCertificateAuthorityResult;
import com.amazonaws.services.acmpca.model.CreateCertificateAuthorityRequest;
import com.amazonaws.services.acmpca.model.CrlConfiguration;
import com.amazonaws.services.acmpca.model.KeyAlgorithm;
import com.amazonaws.services.acmpca.model.SigningAlgorithm;
import com.amazonaws.services.acmpca.model.Tag; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-2 | import com.amazonaws.services.acmpca.model.Tag;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Objects;
import com.amazonaws.services.acmpca.model.GetCertificateAuthorityCsrRequest;
import com.amazonaws.services.acmpca.model.GetCertificateAuthorityCsrResult;
import com.amazonaws.services.acmpca.model.GetCertificateRequest;
import com.amazonaws.services.acmpca.model.GetCertificateResult;
import com.amazonaws.services.acmpca.model.ImportCertificateAuthorityCertificateRequest;
import com.amazonaws.services.acmpca.model.IssueCertificateRequest;
import com.amazonaws.services.acmpca.model.IssueCertificateResult;
import com.amazonaws.services.acmpca.model.SigningAlgorithm;
import com.amazonaws.services.acmpca.model.Validity;
import com.amazonaws.AmazonClientException;
import com.amazonaws.services.acmpca.model.CertificateMismatchException;
import com.amazonaws.services.acmpca.model.ConcurrentModificationException; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-3 | import com.amazonaws.services.acmpca.model.ConcurrentModificationException;
import com.amazonaws.services.acmpca.model.LimitExceededException;
import com.amazonaws.services.acmpca.model.InvalidArgsException;
import com.amazonaws.services.acmpca.model.InvalidArnException;
import com.amazonaws.services.acmpca.model.InvalidPolicyException;
import com.amazonaws.services.acmpca.model.InvalidStateException;
import com.amazonaws.services.acmpca.model.MalformedCertificateException;
import com.amazonaws.services.acmpca.model.MalformedCSRException;
import com.amazonaws.services.acmpca.model.RequestFailedException;
import com.amazonaws.services.acmpca.model.RequestInProgressException;
import com.amazonaws.services.acmpca.model.ResourceNotFoundException;
import com.amazonaws.services.acmpca.model.RevocationConfiguration;
import com.amazonaws.services.acmpca.model.AWSACMPCAException;
import com.amazonaws.waiters.Waiter;
import com.amazonaws.waiters.WaiterParameters;
import com.amazonaws.waiters.WaiterTimedOutException; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-4 | import com.amazonaws.waiters.WaiterParameters;
import com.amazonaws.waiters.WaiterTimedOutException;
import com.amazonaws.waiters.WaiterUnrecoverableException;
public class RootCAActivation {
public static void main(String[] args) throws Exception {
// Define the endpoint region for your sample.
String endpointRegion = "region"; // Substitute your region here, e.g. "us-west-2"
// Define a CA subject.
ASN1Subject subject = new ASN1Subject();
subject.setOrganization("Example Organization");
subject.setOrganizationalUnit("Example");
subject.setCountry("US");
subject.setState("Virginia");
subject.setLocality("Arlington");
subject.setCommonName("www.example.com");
// Define the CA configuration.
CertificateAuthorityConfiguration configCA = new CertificateAuthorityConfiguration();
configCA.withKeyAlgorithm(KeyAlgorithm.RSA_2048);
configCA.withSigningAlgorithm(SigningAlgorithm.SHA256WITHRSA);
configCA.withSubject(subject); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-5 | configCA.withSubject(subject);
// Define a certificate revocation list configuration.
CrlConfiguration crlConfigure = new CrlConfiguration();
crlConfigure.withEnabled(true);
crlConfigure.withExpirationInDays(365);
crlConfigure.withCustomCname(null);
crlConfigure.withS3BucketName("your-bucket-name");
// Define a certificate authority type
CertificateAuthorityType CAtype = CertificateAuthorityType.ROOT;
// ** Execute core code samples for Root CA activation in sequence **
AWSACMPCA client = ClientBuilder(endpointRegion);
String rootCAArn = CreateCertificateAuthority(configCA, crlConfigure, CAtype, client);
String csr = GetCertificateAuthorityCsr(rootCAArn, client);
String rootCertificateArn = IssueCertificate(rootCAArn, csr, client);
String rootCertificate = GetCertificate(rootCertificateArn, rootCAArn, client);
ImportCertificateAuthorityCertificate(rootCertificate, rootCAArn, client);
}
private static AWSACMPCA ClientBuilder(String endpointRegion) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-6 | }
private static AWSACMPCA ClientBuilder(String endpointRegion) {
// Retrieve your credentials from the C:\Users\name\.aws\credentials file
// in Windows or the .aws/credentials file in Linux.
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider("default").getCredentials();
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (C:\\Users\\joneps\\.aws\\credentials), and is in valid format.",
e);
}
String endpointProtocol = "https://acm-pca." + endpointRegion + ".amazonaws.com/";
EndpointConfiguration endpoint =
new AwsClientBuilder.EndpointConfiguration(endpointProtocol, endpointRegion);
// Create a client that you can use to make requests.
AWSACMPCA client = AWSACMPCAClientBuilder.standard()
.withEndpointConfiguration(endpoint)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build(); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-7 | .withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
return client;
}
private static String CreateCertificateAuthority(CertificateAuthorityConfiguration configCA, CrlConfiguration crlConfigure, CertificateAuthorityType CAtype, AWSACMPCA client) {
RevocationConfiguration revokeConfig = new RevocationConfiguration();
revokeConfig.setCrlConfiguration(crlConfigure);
// Create the request object.
CreateCertificateAuthorityRequest createCARequest = new CreateCertificateAuthorityRequest();
createCARequest.withCertificateAuthorityConfiguration(configCA);
createCARequest.withRevocationConfiguration(revokeConfig);
createCARequest.withIdempotencyToken("123987");
createCARequest.withCertificateAuthorityType(CAtype);
// Create the private CA.
CreateCertificateAuthorityResult createCAResult = null;
try {
createCAResult = client.createCertificateAuthority(createCARequest);
} catch (InvalidArgsException ex) {
throw ex;
} catch (InvalidPolicyException ex) { | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-8 | } catch (InvalidArgsException ex) {
throw ex;
} catch (InvalidPolicyException ex) {
throw ex;
} catch (LimitExceededException ex) {
throw ex;
}
// Retrieve the ARN of the private CA.
String rootCAArn = createCAResult.getCertificateAuthorityArn();
System.out.println("Root CA Arn: " + rootCAArn);
return rootCAArn;
}
private static String GetCertificateAuthorityCsr(String rootCAArn, AWSACMPCA client) {
// Create the CSR request object and set the CA ARN.
GetCertificateAuthorityCsrRequest csrRequest = new GetCertificateAuthorityCsrRequest();
csrRequest.withCertificateAuthorityArn(rootCAArn);
// Create waiter to wait on successful creation of the CSR file.
Waiter<GetCertificateAuthorityCsrRequest> getCSRWaiter = client.waiters().certificateAuthorityCSRCreated();
try {
getCSRWaiter.run(new WaiterParameters<>(csrRequest));
} catch (WaiterUnrecoverableException e) {
//Explicit short circuit when the recourse transitions into | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-9 | } catch (WaiterUnrecoverableException e) {
//Explicit short circuit when the recourse transitions into
//an undesired state.
} catch (WaiterTimedOutException e) {
//Failed to transition into desired state even after polling.
} catch (AWSACMPCAException e) {
//Unexpected service exception.
}
// Retrieve the CSR.
GetCertificateAuthorityCsrResult csrResult = null;
try {
csrResult = client.getCertificateAuthorityCsr(csrRequest);
} catch (RequestInProgressException ex) {
throw ex;
} catch (ResourceNotFoundException ex) {
throw ex;
} catch (InvalidArnException ex) {
throw ex;
} catch (RequestFailedException ex) {
throw ex;
}
// Retrieve and display the CSR;
String csr = csrResult.getCsr();
System.out.println(csr);
return csr;
}
private static String IssueCertificate(String rootCAArn, String csr, AWSACMPCA client) {
// Create a certificate request:
IssueCertificateRequest issueRequest = new IssueCertificateRequest(); | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-10 | // Create a certificate request:
IssueCertificateRequest issueRequest = new IssueCertificateRequest();
// Set the CA ARN.
issueRequest.withCertificateAuthorityArn(rootCAArn);
// Set the template ARN.
issueRequest.withTemplateArn("arn:aws:acm-pca:::template/RootCACertificate/V1");
ByteBuffer csrByteBuffer = stringToByteBuffer(csr);
issueRequest.setCsr(csrByteBuffer);
// Set the signing algorithm.
issueRequest.withSigningAlgorithm(SigningAlgorithm.SHA256WITHRSA);
// Set the validity period for the certificate to be issued.
Validity validity = new Validity();
validity.withValue(3650L);
validity.withType("DAYS");
issueRequest.withValidity(validity);
// Set the idempotency token.
issueRequest.setIdempotencyToken("1234");
// Issue the certificate.
IssueCertificateResult issueResult = null;
try {
issueResult = client.issueCertificate(issueRequest);
} catch (LimitExceededException ex) {
throw ex; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-11 | } catch (LimitExceededException ex) {
throw ex;
} catch (ResourceNotFoundException ex) {
throw ex;
} catch (InvalidStateException ex) {
throw ex;
} catch (InvalidArnException ex) {
throw ex;
} catch (InvalidArgsException ex) {
throw ex;
} catch (MalformedCSRException ex) {
throw ex;
}
// Retrieve and display the certificate ARN.
String rootCertificateArn = issueResult.getCertificateArn();
System.out.println("Root Certificate Arn: " + rootCertificateArn);
return rootCertificateArn;
}
private static String GetCertificate(String rootCertificateArn, String rootCAArn, AWSACMPCA client) {
// Create a request object.
GetCertificateRequest certificateRequest = new GetCertificateRequest();
// Set the certificate ARN.
certificateRequest.withCertificateArn(rootCertificateArn);
// Set the certificate authority ARN.
certificateRequest.withCertificateAuthorityArn(rootCAArn);
// Create waiter to wait on successful creation of the certificate file. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-12 | // Create waiter to wait on successful creation of the certificate file.
Waiter<GetCertificateRequest> getCertificateWaiter = client.waiters().certificateIssued();
try {
getCertificateWaiter.run(new WaiterParameters<>(certificateRequest));
} catch (WaiterUnrecoverableException e) {
//Explicit short circuit when the recourse transitions into
//an undesired state.
} catch (WaiterTimedOutException e) {
//Failed to transition into desired state even after polling.
} catch (AWSACMPCAException e) {
//Unexpected service exception.
}
// Retrieve the certificate and certificate chain.
GetCertificateResult certificateResult = null;
try {
certificateResult = client.getCertificate(certificateRequest);
} catch (RequestInProgressException ex) {
throw ex;
} catch (RequestFailedException ex) {
throw ex;
} catch (ResourceNotFoundException ex) {
throw ex;
} catch (InvalidArnException ex) {
throw ex;
} catch (InvalidStateException ex) {
throw ex;
}
// Get the certificate and certificate chain and display the result. | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-13 | throw ex;
}
// Get the certificate and certificate chain and display the result.
String rootCertificate = certificateResult.getCertificate();
System.out.println(rootCertificate);
return rootCertificate;
}
private static void ImportCertificateAuthorityCertificate(String rootCertificate, String rootCAArn, AWSACMPCA client) {
// Create the request object and set the signed certificate, chain and CA ARN.
ImportCertificateAuthorityCertificateRequest importRequest =
new ImportCertificateAuthorityCertificateRequest();
ByteBuffer certByteBuffer = stringToByteBuffer(rootCertificate);
importRequest.setCertificate(certByteBuffer);
importRequest.setCertificateChain(null);
// Set the certificate authority ARN.
importRequest.withCertificateAuthorityArn(rootCAArn);
// Import the certificate.
try {
client.importCertificateAuthorityCertificate(importRequest);
} catch (CertificateMismatchException ex) {
throw ex;
} catch (MalformedCertificateException ex) {
throw ex; | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
fba22601609b-14 | throw ex;
} catch (MalformedCertificateException ex) {
throw ex;
} catch (InvalidArnException ex) {
throw ex;
} catch (ResourceNotFoundException ex) {
throw ex;
} catch (RequestInProgressException ex) {
throw ex;
} catch (ConcurrentModificationException ex) {
throw ex;
} catch (RequestFailedException ex) {
throw ex;
}
System.out.println("Root CA certificate successfully imported.");
System.out.println("Root CA activated successfully.");
}
private static ByteBuffer stringToByteBuffer(final String string) {
if (Objects.isNull(string)) {
return null;
}
byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
return ByteBuffer.wrap(bytes);
}
}
``` | https://github.com/siagholami/aws-documentation/tree/main/documents/aws-private-ca-user-guide/doc_source/JavaApi-ActivateRootCA.md |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.