Skip to content

Commit 897e221

Browse files
authored
Demo http S3 generate presigned url - generate not only GET but also PUT (for http S3 upload demo) (#1933)
presigned URL demo - generate not only GET but also PUT (for S3 upload demo) updated documentation Update demos/http/http_demo_s3_generate_presigned_url/http_demo_s3_generate_presigned_url.c
1 parent 60e1ef5 commit 897e221

File tree

11 files changed

+121
-116
lines changed

11 files changed

+121
-116
lines changed

.github/links_allowlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ https://www.somewebsite.com/path/to/item.txt?optionalquery=stuff
44
https://dummy-url.com/ota.bin
55
file://template.json
66
file://policy.json
7+
https://www.gnu.org/software/complexity/manual/complexity.html

.github/workflows/ci.yml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -197,30 +197,10 @@ jobs:
197197
runs-on: ubuntu-20.04
198198
steps:
199199
- uses: actions/checkout@v2
200-
- name: Install Uncrustify
201-
run: sudo apt-get install uncrustify
202-
- name: Check Formatting With Uncrustify
203-
run: find . -iname "*.[hc]" -exec uncrustify --check -c tools/uncrustify.cfg {} +
204-
- name: Check For Trailing Whitespace
205-
run: |
206-
set +e
207-
grep --exclude="README.md" -rnI -e "[[:blank:]]$" .
208-
if [ "$?" = "0" ]; then
209-
echo "Files have trailing whitespace."
210-
exit 1
211-
else
212-
exit 0
213-
fi
214-
- name: Check for CRLF
215-
run: |
216-
set +e
217-
find . -path ./.git -prune -o -exec file {} + | grep "CRLF"
218-
if [ "$?" = "0" ]; then
219-
echo "Files have CRLF line endings."
220-
exit 1
221-
else
222-
exit 0
223-
fi
200+
- name: Check formatting
201+
uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
202+
with:
203+
path: ./
224204
doxygen:
225205
runs-on: ubuntu-latest
226206
steps:
@@ -230,7 +210,7 @@ jobs:
230210
- name: Install Doxygen
231211
run: |
232212
wget -qO- "https://sourceforge.net/projects/doxygen/files/rel-1.9.6/doxygen-1.9.6.linux.bin.tar.gz/download" | sudo tar --strip-components=1 -xz -C /usr/local
233-
sudo apt-get install -y libclang-11-dev libclang-cpp11 graphviz
213+
sudo apt-get install -y libclang-18-dev libclang-cpp18 graphviz
234214
- name: Install Python3
235215
uses: actions/setup-python@v2
236216
with:

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ In order to set these configurations manually, edit `demo_config.h` in `demos/ht
470470
* Set `S3_PRESIGNED_GET_URL` to a S3 presigned URL with GET access.
471471
* Set `S3_PRESIGNED_PUT_URL` to a S3 presigned URL with PUT access.
472472

473-
You can generate the presigned urls using [demos/http/common/src/presigned_urls_gen.py](demos/http/common/src/presigned_urls_gen.py). More info can be found [here](demos/http/common/src/README.md).
473+
You can generate the presigned urls using [demos/http/common/src/presigned_urls_gen.py](demos/http/common/src/presigned_urls_gen.py) (more info can be found [here](demos/http/common/src/README.md)) or [demos/http/http_demo_s3_generate_presigned_url/README.md](demos/http/http_demo_s3_generate_presigned_url/README.md).
474474

475475
#### Configure S3 Download HTTP Demo using SigV4 Library:
476476

@@ -503,13 +503,13 @@ The following creates a job that specifies a Linux Kernel link for downloading.
503503
--document '{"url":"https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.8.5.tar.xz"}'
504504
```
505505
3. Run the demo using this command:
506-
```
506+
```
507507
./build/bin/jobs_demo_mosquitto \
508508
-n <thing-name> \
509509
-h <aws-iot endpoint> \
510510
--certfile <device certificate of the thing> \
511511
--keyfile <private key of the thing>
512-
```
512+
```
513513
Note: Replace the placeholders in angle brackets with your specific information.
514514

515515

@@ -670,7 +670,7 @@ First, install Tunnelmole. On Linux, Mac and Windows Subsystem for Linux, use
670670
```sh
671671
curl -O https://tunnelmole.com/sh/install.sh && sudo bash install.sh
672672
```
673-
The above may not function correctly on ARM machines like mac. As an alternative, you can clone the repository and build the application from its source code.
673+
The above may not function correctly on ARM machines like mac. As an alternative, you can clone the repository and build the application from its source code.
674674
For Windows without WSL, [download tmole.exe](https://tunnelmole.com/downloads/tmole.exe) and add it to your [PATH](https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows).
675675

676676
Then run `tmole 80`

demos/fleet_provisioning/fleet_provisioning_keys_cert/fleet_provisioning_keys_cert_demo.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -772,57 +772,57 @@ int main( int argc,
772772
LogInfo( ( "Demo completed successfully." ) );
773773

774774
#if defined( DOWNLOADED_CERT_WRITE_PATH )
775+
{
776+
int fd = open( DOWNLOADED_CERT_WRITE_PATH, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR );
777+
778+
if( -1 != fd )
775779
{
776-
int fd = open( DOWNLOADED_CERT_WRITE_PATH, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR );
780+
const ssize_t writtenBytes = write( fd, certificate, certificateLength );
777781

778-
if( -1 != fd )
782+
if( writtenBytes == certificateLength )
779783
{
780-
const ssize_t writtenBytes = write( fd, certificate, certificateLength );
781-
782-
if( writtenBytes == certificateLength )
783-
{
784-
LogInfo( ( "Written %s successfully.", DOWNLOADED_CERT_WRITE_PATH ) );
785-
}
786-
else
787-
{
788-
LogError( ( "Could not write to %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
789-
}
790-
791-
close( fd );
784+
LogInfo( ( "Written %s successfully.", DOWNLOADED_CERT_WRITE_PATH ) );
792785
}
793786
else
794787
{
795-
LogError( ( "Could not open %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
788+
LogError( ( "Could not write to %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
796789
}
790+
791+
close( fd );
797792
}
793+
else
794+
{
795+
LogError( ( "Could not open %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
796+
}
797+
}
798798
#else /* if defined( DOWNLOADED_CERT_WRITE_PATH ) */
799799
LogInfo( ( "NOTE: define DOWNLOADED_CERT_WRITE_PATH in order to have the certificate written to disk." ) );
800800
#endif // DOWNLOADED_CERT_WRITE_PATH
801801

802802
#if defined( DOWNLOADED_PRIVATE_KEY_WRITE_PATH )
803+
{
804+
int fd = open( DOWNLOADED_PRIVATE_KEY_WRITE_PATH, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR );
805+
806+
if( -1 != fd )
803807
{
804-
int fd = open( DOWNLOADED_PRIVATE_KEY_WRITE_PATH, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR );
808+
const ssize_t writtenBytes = write( fd, privatekey, privatekeyLength );
805809

806-
if( -1 != fd )
810+
if( writtenBytes == privatekeyLength )
807811
{
808-
const ssize_t writtenBytes = write( fd, privatekey, privatekeyLength );
809-
810-
if( writtenBytes == privatekeyLength )
811-
{
812-
LogInfo( ( "Written %s successfully.", DOWNLOADED_PRIVATE_KEY_WRITE_PATH ) );
813-
}
814-
else
815-
{
816-
LogError( ( "Could not write to %s. Error: %s.", DOWNLOADED_PRIVATE_KEY_WRITE_PATH, strerror( errno ) ) );
817-
}
818-
819-
close( fd );
812+
LogInfo( ( "Written %s successfully.", DOWNLOADED_PRIVATE_KEY_WRITE_PATH ) );
820813
}
821814
else
822815
{
823-
LogError( ( "Could not open %s. Error: %s.", DOWNLOADED_PRIVATE_KEY_WRITE_PATH, strerror( errno ) ) );
816+
LogError( ( "Could not write to %s. Error: %s.", DOWNLOADED_PRIVATE_KEY_WRITE_PATH, strerror( errno ) ) );
824817
}
818+
819+
close( fd );
825820
}
821+
else
822+
{
823+
LogError( ( "Could not open %s. Error: %s.", DOWNLOADED_PRIVATE_KEY_WRITE_PATH, strerror( errno ) ) );
824+
}
825+
}
826826
#else /* if defined( DOWNLOADED_PRIVATE_KEY_WRITE_PATH ) */
827827
LogInfo( ( "NOTE: define DOWNLOADED_PRIVATE_KEY_WRITE_PATH in order to have the private key written to disk." ) );
828828
#endif // DOWNLOADED_PRIVATE_KEY_WRITE_PATH

demos/fleet_provisioning/fleet_provisioning_with_csr/fleet_provisioning_with_csr_demo.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -783,29 +783,29 @@ int main( int argc,
783783
LogInfo( ( "Demo completed successfully." ) );
784784

785785
#if defined( DOWNLOADED_CERT_WRITE_PATH )
786+
{
787+
int fd = open( DOWNLOADED_CERT_WRITE_PATH, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR );
788+
789+
if( -1 != fd )
786790
{
787-
int fd = open( DOWNLOADED_CERT_WRITE_PATH, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR );
791+
const ssize_t writtenBytes = write( fd, certificate, certificateLength );
788792

789-
if( -1 != fd )
793+
if( writtenBytes == certificateLength )
790794
{
791-
const ssize_t writtenBytes = write( fd, certificate, certificateLength );
792-
793-
if( writtenBytes == certificateLength )
794-
{
795-
LogInfo( ( "Written %s successfully.", DOWNLOADED_CERT_WRITE_PATH ) );
796-
}
797-
else
798-
{
799-
LogError( ( "Could not write to %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
800-
}
801-
802-
close( fd );
795+
LogInfo( ( "Written %s successfully.", DOWNLOADED_CERT_WRITE_PATH ) );
803796
}
804797
else
805798
{
806-
LogError( ( "Could not open %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
799+
LogError( ( "Could not write to %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
807800
}
801+
802+
close( fd );
808803
}
804+
else
805+
{
806+
LogError( ( "Could not open %s. Error: %s.", DOWNLOADED_CERT_WRITE_PATH, strerror( errno ) ) );
807+
}
808+
}
809809
#else /* if defined( DOWNLOADED_CERT_WRITE_PATH ) */
810810
LogInfo( ( "NOTE: define DOWNLOADED_CERT_WRITE_PATH in order to have the certificate written to disk." ) );
811811
#endif // DOWNLOADED_CERT_WRITE_PATH

demos/greengrass/greengrass_demo_local_auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Next you will need to set up a Root CA for your Greengrass device.
5252

5353
On the Greengrass core, run the following:
5454

55-
1. Create private key for the CA certificate
55+
1. Create private key for the CA certificate
5656
```sh
5757
openssl genrsa -out ca.key 2048
5858
```

demos/http/common/src/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
```
1717

1818
1. You will need an AWS Account with S3 access before beginning. You must install and configure the AWS CLI in order to
19-
use this script.
20-
For information on AWS S3 please see: https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html
21-
For AWS CLI installation information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
19+
use this script.
20+
For information on AWS S3 please see: https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html
21+
For AWS CLI installation information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
2222
For AWS CLI configuration information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
2323

2424
```sh

demos/http/http_demo_s3_download/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Following steps needs to be followed to configure HTTP S3 Download Demo to use S
44

55
### Prerequisites
66

7-
1. You will need an AWS Account with S3 access before beginning. You must be familiar with AWS IoT and IAM to perform steps using the AWS CLI. You must install and configure the AWS CLI in order to follow the steps.
8-
For information on AWS S3 please see: https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html
9-
For AWS CLI installation information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
7+
1. You will need an AWS Account with S3 access before beginning. You must be familiar with AWS IoT and IAM to perform steps using the AWS CLI. You must install and configure the AWS CLI in order to follow the steps.
8+
For information on AWS S3 please see: https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html
9+
For AWS CLI installation information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
1010
For AWS CLI configuration information please see: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html
1111

1212
```sh
@@ -15,7 +15,7 @@ Following steps needs to be followed to configure HTTP S3 Download Demo to use S
1515

1616
### Detailed Steps
1717

18-
#### 1. Create an AWS IoT thing:
18+
#### 1. Create an AWS IoT thing:
1919

2020
You may utilize an already existing AWS IoT Thing or create a new one in the IoT Core section of the AWS Management Console UI.
2121

@@ -37,8 +37,8 @@ Run the following command in the AWS CLI to attach the device certificate to you
3737
```sh
3838
aws iot attach-thing-principal --thing-name device_thing_name --principal <certificate-arn>
3939
```
40-
41-
#### 3. Configure an IAM role:
40+
41+
#### 3. Configure an IAM role:
4242

4343
Next, configure an IAM role in your AWS account that will be assumed by the credentials provider on behalf of your device. You are required to associate two policies with the role: a trust policy that controls who can assume the role, and an access policy that controls which actions can be performed on which resources by assuming the role.
4444

@@ -108,8 +108,8 @@ Now, run the following command to attach the policy to the IAM user.
108108
aws iam attach-user-policy --policy-arn arn:aws:iam::<your_aws_account_id>:policy/passrolepermission --user-name <user_name>
109109
```
110110

111-
#### 4. Create a role alias:
112-
111+
#### 4. Create a role alias:
112+
113113
Now that you have configured the IAM role, you will create a role alias with AWS IoT. You must provide the following pieces of information when creating a role alias:
114114

115115
RoleAlias: This is the primary key of the role alias data model and hence a mandatory attribute. It is a string; the minimum length is 1 character, and the maximum length is 128 characters.
@@ -120,7 +120,7 @@ Run the following command in the AWS CLI to create a role alias. Use the credent
120120
aws iot create-role-alias --role-alias name-s3-access-role-alias --role-arn arn:aws:iam::<your_aws_account_id>:role/s3-access-role --credential-duration-seconds 3600
121121
```
122122

123-
#### 5. Attach a policy:
123+
#### 5. Attach a policy:
124124
You created and registered a certificate with AWS IoT earlier for successful authentication of your device. Now, you need to create and attach a policy to the certificate to authorize the request for the security token.
125125
```
126126
{
@@ -143,8 +143,8 @@ Use the following command to attach the policy with the certificate you register
143143
aws iot attach-policy --policy-name Thing_Policy_Name --target <certificate-arn>
144144
```
145145

146-
#### 6. Request a security token:
147-
146+
#### 6. Request a security token:
147+
148148
Make an HTTPS request to the credentials provider to fetch a security token. You have to supply the following information:
149149

150150
Certificate and key pair: Because this is an HTTP request over TLS mutual authentication, you have to provide the certificate and the corresponding key pair to your client while making the request. Use the same certificate and key pair that you used during certificate registration with AWS IoT.
@@ -174,13 +174,13 @@ The following is sample output of the describe-endpoint command. It contains the
174174
175175
#### 8. After the following the above steps, configure the below macros in `demo_config.h`.
176176
```c
177-
#define AWS_IOT_THING_NAME "Name of IOT Thing that you provided in STEP 1"
177+
#define AWS_IOT_THING_NAME "Name of IOT Thing that you provided in STEP 1"
178178
#define AWS_IOT_CREDENTIAL_PROVIDER_ROLE "Name of ROLE ALIAS that you provided in STEP 4"
179179
#define AWS_S3_BUCKET_NAME "Name of Bucket that contains the object that needs to be downloaded"
180180
#define AWS_S3_BUCKET_REGION "Region where Bucket is located"
181181
#define AWS_S3_OBJECT_NAME "Name of object that needs to be downloaded from AWS S3"
182182
```
183-
183+
184184
### Parameters
185185

186186
#### device_thing_name

0 commit comments

Comments
 (0)